Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-30287

Environment variables are not expanded in tag names when publishing

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • git-plugin

      I'm using the Git Publisher post-build action to try and push a tag that was created during the build.

      The tag name is placed into an environment variable via the line:

      export BUILD_VERSION=`node -e "console.log(require('./package.json').version);"`
      

      The Git Publisher is then configured to push the Tag $BUILD_VERSION

      Rather than push it, I get an error in my build console:

         > git tag -l $BUILD_VERSION # timeout=10
      ERROR: Publisher hudson.plugins.git.GitPublisher aborted due to exception
      hudson.AbortException: Tag $BUILD_VERSION does not exist and Create Tag is not specified, so failing.
      	at hudson.plugins.git.GitPublisher.perform(GitPublisher.java:287)
      	at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:770)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:734)
      	at hudson.model.Build$BuildExecution.post2(Build.java:183)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:683)
      	at hudson.model.Run.execute(Run.java:1784)
      	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      	at hudson.model.ResourceController.execute(ResourceController.java:89)
      	at hudson.model.Executor.run(Executor.java:240)
      

          [JENKINS-30287] Environment variables are not expanded in tag names when publishing

          Dan Rumney added a comment -

          Line 268 of GitPublisher.java is:

                              final String tagName = environment.expand(t.getTagName());
          

          which indicates that this should work... however, I wonder whether environment includes variables added during the build.

          Dan Rumney added a comment - Line 268 of GitPublisher.java is: final String tagName = environment.expand(t.getTagName()); which indicates that this should work... however, I wonder whether environment includes variables added during the build.

          Mark Waite added a comment -

          Could you review JENKINS-24786 to see if there is useful information in that bug report which might help you?

          Mark Waite added a comment - Could you review JENKINS-24786 to see if there is useful information in that bug report which might help you?

          This is not a problem with Git plugin. This is a common problem, that makes build environment variables be gone at Post-Build actions.

          What you need to do is to export the variable to a temporary file, and re-read this file into environment as the first of Post-Build Actions.

          In the Build section:
          echo <your variable>=%<your variable>% > temp.var

          In the Post-Build section, add "Execute a set of scripts" => Build steps => Inject environment variables.
          Set Properties File Path to temp.var

          Mattias Vannergård added a comment - This is not a problem with Git plugin. This is a common problem, that makes build environment variables be gone at Post-Build actions. What you need to do is to export the variable to a temporary file, and re-read this file into environment as the first of Post-Build Actions. In the Build section: echo <your variable>=%<your variable>% > temp.var In the Post-Build section, add "Execute a set of scripts" => Build steps => Inject environment variables. Set Properties File Path to temp.var

          Bo3b Johnson added a comment -

          Thought I'd update this bug with current status. I'm also seeing this problem on the latest beta of 2.5.0-beta5.

          No regular environment variables are expanded. I'm not certain that it is only the Post-Build shell being different, because if I create a post-build task and set environment variables there, then they are still ignored/lost by Git Publisher.

          If I use the Inject Environment variables plugin, I can save the variables into a file in the normal build, then load them at post-build with Inject Environment variables. The variables appear to be read properly, but only the last variable in the file is available for expansion.

          So... a workaround I can use for now is to put a full version string into a single variable, Inject that variable at post-build, and then I can use that single variable in Git Publisher to Tag the version.

          Bo3b Johnson added a comment - Thought I'd update this bug with current status. I'm also seeing this problem on the latest beta of 2.5.0-beta5. No regular environment variables are expanded. I'm not certain that it is only the Post-Build shell being different, because if I create a post-build task and set environment variables there, then they are still ignored/lost by Git Publisher. If I use the Inject Environment variables plugin, I can save the variables into a file in the normal build, then load them at post-build with Inject Environment variables. The variables appear to be read properly, but only the last variable in the file is available for expansion. So... a workaround I can use for now is to put a full version string into a single variable, Inject that variable at post-build, and then I can use that single variable in Git Publisher to Tag the version.

            Unassigned Unassigned
            dancrumb Dan Rumney
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: