Tagging github from Jenkins job Tagging github from Jenkins job jenkins jenkins

Tagging github from Jenkins job


It is expected Failure,Tag To Push in Git publisher plugin allows usage of environment variables. But the variable value you have created is a local variable and has the scope with in that execute shell and will not be passed to post build step.

How to fix this:

add below:

echo "TAG_TO_PUSH=${APP_BUILD_TAG}" > releaseStamp.txt

and then use a inject environment build/post build step and inject this file. This will export this variable to entire jenkins job. So that your Tag To Push will also be able to consume the variable value.

Now in the Tag to push section, use the value below:

${TAG_TO_PUSH}


The EnvInject plugin won't let you generate a tag programmatically. To work around this I found it necessary to use the EnvInject plugin twice -- once at the beginning, to generate the property/tag as a file, and once after SCM checkout, to read the file.

Using your example:

  1. Ensure you have the EnvInject plugin installed.
  2. Edit your Jenkins configuration. Under 'General', check 'Prepare anenvironment for the run' (this section will be executed at thebeginning).
  3. In the 'Script content' text field, type:echo "APP_BUILD_TAG=$(date +'%Y%m%d_%H%M')" > /path/to/stamp.txt
  4. Scroll down to 'Build Environment'. Check 'Inject environmentvariables into the build process' (this section will be executedafter SCM checkout).
  5. In the 'Properties file path' text field, type: /path/to/stamp.txt
  6. Scroll to Post-build actions, check the Git Publisher plugin, add atag. In the 'Tag to push' text field, type: ${APP_BUILD_TAG}

(Whether or not this is best-practice is anyone's guess; it seems like there should be an easier way, but this is the only way I could get it to work.)