Skip to content

Add GraphQL mutation to approve or reject deployment

What does this MR do and why?

This merge request adds a new GraphQL mutation to approve or reject a deployment.

Please note: I followed the naming conventions section of the GraphQL API style guide when choosing the name of this mutation.

Resolves #388527 (closed).

How to set up and validate locally

To validate locally, please follow the steps below.

  • In your local GDK setup, create a new project if you don't have one already.
  • Inside that project, create an environment in Deployments > Environments.
  • Protect the environment you had just created in Settings > CI/CD > Protected Environments.
  • Add the following .gitlab-ci.yml file to the project:
image: alpine:latest

say_test:
  stage: test
  script: echo 'testing..'

deploy_production:
  stage: deploy
  script:
    - echo 'deploying..'
    - echo 'deployed!'
  environment: production
  • Run a pipeline inside the project from CI/CD > Pipelines.
  • Ensure a deployment is created in Deployments > Environments. The deployment should be blocked waiting for approval.
  • Log out of your account, and then login using a different user.
  • Visit GraphiQL Explorer on your local GitLab instance.
  • Paste the GraphQL query from the section below. Make sure to replace DEPLOYMENT_ID with the actual deployment id.
  • Verify the deployment is approved and the deploy_job is green.

Note: You can do the same steps above to also reject the deployment.

Query Example

mutation {
  approveDeployment(
    input: {id: "gid://gitlab/Deployment/DEPLOYMENT_ID", status: APPROVED, comment: "Nice one!"}
  ) {
    deploymentApproval {
      comment
      createdAt
      status
      updatedAt
    }
    errors
  }
}

Response

{
  "data": {
    "approveDeployment": {
      "deploymentApproval": {
        "comment": "Nice one!",
        "createdAt": "2023-02-15T10:15:51Z",
        "status": "APPROVED",
        "updatedAt": "2023-02-15T10:15:51Z"
      },
      "errors": []
    }
  }
}

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Ahmed Hemdan

Merge request reports

Loading