문제

I'm using Jenkins for CI on my project. Right now, I have a "Dev" build, which is triggered by Stash (git server) any time a commit is made to any branch.

I'm trying to incorporate my release workflow as well. Here's the plan:

  • Dev job uses the Promoted Builds plugin to promote all builds to master
  • Release job is triggered by the promotion of Dev

However, I can't seem to figure out how to promote a build based on its branch. I've tried the "promote immediately based on build parameters" and specified the GIT_BRANCH to be origin/master. When I run the build, I echo %GIT_BRANCH% and it prints origin/master when it's supposed to.

I also tried adding a string parameter BRANCH to the build and set BRANCH=%GIT_BRANCH% in my build script in case it actually needs to be a parameter rather than just an environment variable.

Still stumped.

도움이 되었습니까?

해결책

Finally figured it out. Added a String build parameter called IS_RELEASE_CANDIDATE with a default value of 0. I'm using "Promote immediately once the build is complete based on build parameters" with the condition that IS_RELEASE_CANDIDATE is 1.

In my build steps, I've added a Conditional step using the Conditional BuildStep Plugin to be run when the strings $GIT_BRANCH and stash/master match.

If they match, I use the EnvInject Plugin to set IS_RELEASE_CANDIDATE=1.

다른 팁

I was able to do this by using the Custom Groovy Script option, which is provided a build object from which you can access environment variables. This script will only allow promotions on builds that match the origin/master branch.

Screenshot of configuration

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top