NA0606
NA0606

Reputation: 65

select specific Git branch in Jenkins Declarative pipeline

I am trying to select branches with branch names starting with release.

stage("Upload Artifacts") {
      when {
          expression {
              return env.BRANCH_NAME == "release/*"
          }
      }
      steps {
          ...
          ...
      }
 }

The above code is not picking up my release branch and is simply skipping the stage.

Stage "Upload Artifacts" skipped due to when conditional

Upvotes: 0

Views: 348

Answers (2)

NA0606
NA0606

Reputation: 65

when {
     expression {
         return (env.BRANCH_NAME).startsWith('release')
    }
}

Upvotes: 0

smelm
smelm

Reputation: 1334

You are comparing the branch name with the verbatim string release/*. If there is only one branch called "release" just compare with that. If you wanted to use the * as a wild card you should use BRANCH_NAME.startsWith('release') or look into patterns in groovy.

Upvotes: 2

Related Questions