Skip to content

Rename `previousStageJobsAndNeeds` and update return

Laura Montemayor requested to merge refactor-execution-requirements into master

What does this MR do and why?

In order to correctly show the execution order of jobs, previousStageJobsAndNeeds was renamed to a more appropriate name and updated with some requirements that we need to show the correct execution order for jobs.

This MR (ex simplified, full response available below):

  • Rename field from previousStageJobsAndNeeds to previousStageJobsOrNeeds

  • Return previousStageJobsOrNeeds: [someNeed] if there are explicit needs needs: [someNeed] - so ONLY the explicit needs with no jobs from previous stages.

    job: 
      needs: [job_needed] 

    will return: previousStageJobsOrNeeds: [job_needed]

  • Return empty previousStageJobsOrNeeds: [] if there are needs stated with an empty array needs: []

    job: 
      needs: [] 

    will return: previousStageJobsOrNeeds: []

  • Return the jobs from previous stages for a build that has NO needs previousStageJobsOrNeeds: [prevstagejob1, prevstagejob2] self explanatory

Sample `gitlab-ci.yml` used
stages:          # List of stages for jobs, and their order of execution
  - build
  - test
  - deploy

build-job:       # This job runs in the build stage, which runs first.
  stage: build
  script:
    - echo "Compiling the code..."
    - echo "Compile complete."

unit-test-job:   # This job runs in the test stage.
  stage: test    # It only starts when the job in the build stage completes successfully.
  script:
    - echo "Running unit tests... This will take about 60 seconds."
    - sleep 60
    - echo "Code coverage is 90%"

i-dont-need-needs-but-have-array:
  stage: test
  needs: []
  script: 
    - echo "hey"

lint-test-job:   # This job also runs in the test stage.
  stage: test    # It can run at the same time as unit-test-job (in parallel).
  script:
    - echo "Linting code... This will take about 10 seconds."
    - sleep 10
    - echo "No lint issues found."

deploy-job:      # This job runs in the deploy stage.
  stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.
  needs: [build-job]
  script:
    - echo "Deploying application..."
    - echo "Application successfully deployed."
Example query:
{
  project(fullPath: "root/need-and-previous-stages") {
    pipeline(iid: "3") {
      jobs {
        nodes {
          name
          needs{
            nodes{
              name
            }
          }
          executionRequirements {
            nodes {
              name
            }
          }
        }
      }
    }
  }
}
Response
{
  "data": {
    "project": {
      "pipeline": {
        "jobs": {
          "nodes": [
            {
              "name": "lint-test-job",
              "needs": {
                "nodes": []
              },
              "previousStageJobsOrNeeds": {
                "nodes": [
                  {
                    "name": "build-job"
                  }
                ]
              }
            },
            {
              "name": "unit-test-job",
              "needs": {
                "nodes": []
              },
              "previousStageJobsOrNeeds": {
                "nodes": [
                  {
                    "name": "build-job"
                  }
                ]
              }
            },
            {
              "name": "deploy-job",
              "needs": {
                "nodes": [
                  {
                    "name": "build-job"
                  }
                ]
              },
              "previousStageJobsOrNeeds": {
                "nodes": [
                  {
                    "name": "build-job"
                  }
                ]
              }
            },
            {
              "name": "build-job",
              "needs": {
                "nodes": []
              },
              "previousStageJobsOrNeeds": {
                "nodes": []
              }
            },
            {
              "name": "i-dont-need-needs-but-have-array",
              "needs": {
                "nodes": []
              },
              "previousStageJobsOrNeeds": {
                "nodes": []
              }
            }
          ]
        }
      }
    }
  }
}

MR acceptance checklist

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

#346492 (closed)

Edited by Laura Montemayor

Merge request reports