Azure YAML-Pipeline skips jobs and I have no idea why

15.9k Views Asked by At

Even though I set System.Debug=True I get no other information than "The job was skipped". Literally just these four words.

I created a YAML-Release pipeline on Azure Devops which basically runs the jobs:

  • job: build_release
  • jobs: deployment: deploy_test
  • jobs: deployment: deploy_stage

To test the behavior I first only ran the first two jobs and deployed to TEST. Now I want to deploy to STAGE but it seems that the pipeline is only working when I start from the beginning / create a new release. But what I want to do right now is to deploy the already existing release from TEST to STAGE. When I try to do that by rerunning the pipeline Azure just skips all steps. Why is this happening? How can I avoid this and rerun the pipeline? I did not set any conditions.

EDIT with additonal info:

Structure of the pipeline


trigger:
    - release/*

variables:
     ...

resources:
    -   repo: self


pool:
    vmImage: $(vmImageName)

stages:
    -   stage: build_release
        displayName: 'awesome build'
        condition: contains(variables['Build.SourceBranchName'], 'release/')
        jobs:
            -   job: build_release
                steps:
                    ...

    -   stage: deploy_test
        displayName: 'awesome test deploy'
        jobs:
            -   deployment: deploy_test
                environment: 'test'
                strategy:
                    runOnce:
                        deploy:
                            steps:
                               ...

    -   stage: deploy_stage
        displayName: 'awesome stage deploy'
        jobs:
            -   deployment: deploy_stage
                environment: 'stage'
                strategy:
                    runOnce:
                        deploy:
                            steps:
                               ...

I tried to trigger it in two different ways which had the same outcome (everything was skipped): A. I created a new release which was a copy of the previously deployed release. B. I clicked on run pipeline.

2

There are 2 best solutions below

2
On BEST ANSWER

The issue is caused by the condition condition: contains(variables['Build.SourceBranchName'], 'release/'), which you specified for stage build_release.

When the trigger is set to - release/*. The variable variables['Build.SourceBranchName'] will be evaluated to the branch name after the /.

For example:

If you triggered your pipeline from branch release/release1.0. the value of variables['Build.SourceBranchName'] will be release1.0 instead of release/release1.0. So the condition contains(variables['Build.SourceBranchName'], 'release/') will always be false, which caused the stage build_release to be skipped.

enter image description here

And, if you didnot specify dependency for stage deploy_test and stage deploy_stage, the next stage will depends on the previous stage by default. So these two stages also got skipped, since stage build_release is skipped. This is why you saw all the steps were skipped.

enter image description here

Solution:

Using variable Build.SourceBranch in the condition.

Change the condition like below: (The yaml file in the release branches should also be changed like below)

- stage: build_release
  displayName: 'awesome build'
  condition: contains(variables['Build.SourceBranch'], 'release/') #use Build.SourceBranch

Noted: If you mannaly triggered your pipeline. Please make sure your select to trigger the pipeline from release branches. Or the pipeline will be triggered from main branch by default.

enter image description here

0
On

The issue here is when the run of the pipeline was create it sounds like the deploy stage was not selected. As such at compilation time of the pipeline the stage was skipped as it was defined as being skipped within that run.

As for what you are running the first question would be are these changes to run the deploy_stage is this in the main branch? The pipeline by default will run against the main branch unless otherwise specified.