[JIRA] (JENKINS-37238) Problems expanding variables created outside the Jenkins build

19 views
Skip to first unread message

pavel@batanov.me (JIRA)

unread,
Aug 7, 2016, 7:16:05 AM8/7/16
to jenkinsc...@googlegroups.com
Pavel Batanov created an issue
 
Jenkins / Bug JENKINS-37238
Problems expanding variables created outside the Jenkins build
Issue Type: Bug Bug
Assignee: Alex Earl
Components: token-macro-plugin
Created: 2016/Aug/07 11:15 AM
Labels: token-macro
Priority: Critical Critical
Reporter: Pavel Batanov

Some plugins stopped to work when macros are putted to expand. That worked well before. You can see almost identical stacktrace

https://issues.jenkins-ci.org/browse/JENKINS-37222
https://github.com/jenkinsci/stashnotifier-plugin/issues/117

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

slide.o.mix@gmail.com (JIRA)

unread,
Aug 7, 2016, 7:37:01 AM8/7/16
to jenkinsc...@googlegroups.com
Alex Earl commented on Bug JENKINS-37238
 
Re: Problems expanding variables created outside the Jenkins build

It looks like you are using the beta release, which means this is not critical.

pavel@batanov.me (JIRA)

unread,
Aug 7, 2016, 7:40:01 AM8/7/16
to jenkinsc...@googlegroups.com

Yeah, really the beta one. I think you should add compatibility section to your pom.xml to warn users that this version is not compatible with earlies ones

https://wiki.jenkins-ci.org/display/JENKINS/Marking+a+new+plugin+version+as+incompatible+with+older+versions

pavel@batanov.me (JIRA)

unread,
Aug 7, 2016, 7:41:01 AM8/7/16
to jenkinsc...@googlegroups.com

slide.o.mix@gmail.com (JIRA)

unread,
Aug 7, 2016, 7:42:01 AM8/7/16
to jenkinsc...@googlegroups.com
Alex Earl commented on Bug JENKINS-37238
 
Re: Problems expanding variables created outside the Jenkins build

The plugin IS compatible with earlier versions. It's just still under test, which is why it is released as a beta.

pavel@batanov.me (JIRA)

unread,
Aug 7, 2016, 7:45:01 AM8/7/16
to jenkinsc...@googlegroups.com

sbaumkirchner@conversantmedia.net (JIRA)

unread,
Aug 8, 2016, 1:39:01 PM8/8/16
to jenkinsc...@googlegroups.com

I put in the original ticket for the stash-updater plugin, Which version of the token macro plugin is needed to avoid the following bug:

17:33:19 org.jenkinsci.plugins.tokenmacro.MacroEvaluationException: Unrecognized macro 'FOO' in '$FOO'
17:33:19 at org.jenkinsci.plugins.tokenmacro.TokenMacro.expand(TokenMacro.java:198)
17:33:19 at org.jenkinsci.plugins.tokenmacro.TokenMacro.expandAll(TokenMacro.java:233)
17:33:19 at org.jenkinsci.plugins.tokenmacro.TokenMacro.expandAll(TokenMacro.java:222)
17:33:19 at org.jenkinsci.plugins.stashNotifier.StashNotifier.lookupCommitSha1s(StashNotifier.java:287)
17:33:19 at org.jenkinsci.plugins.stashNotifier.StashNotifier.processJenkinsEvent(StashNotifier.java:247)
17:33:19 at org.jenkinsci.plugins.stashNotifier.StashNotifier.prebuild(StashNotifier.java:194)
17:33:19 at hudson.model.AbstractBuild$AbstractBuildExecution.preBuild(AbstractBuild.java:837)
17:33:19 at hudson.model.AbstractBuild$AbstractBuildExecution.preBuild(AbstractBuild.java:832)
17:33:19 at hudson.model.Build$BuildExecution.doRun(Build.java:144)
17:33:19 at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
17:33:19 at hudson.model.Run.execute(Run.java:1738)
17:33:19 at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
17:33:19 at hudson.model.ResourceController.execute(ResourceController.java:98)
17:33:19 at hudson.model.Executor.run(Executor.java:410)

I'm at 1.9 now, i've tried 1.10 as well as 1.21

slide.o.mix@gmail.com (JIRA)

unread,
Aug 8, 2016, 1:59:01 PM8/8/16
to jenkinsc...@googlegroups.com

sbaumkirchner@conversantmedia.net (JIRA)

unread,
Aug 8, 2016, 2:27:01 PM8/8/16
to jenkinsc...@googlegroups.com

no the above errors are from the 1.9 version of token-macro. I'm using jenkins version: 1.655 as well.

slide.o.mix@gmail.com (JIRA)

unread,
Aug 8, 2016, 2:31:01 PM8/8/16
to jenkinsc...@googlegroups.com

slide.o.mix@gmail.com (JIRA)

unread,
Aug 8, 2016, 2:31:01 PM8/8/16
to jenkinsc...@googlegroups.com

Please try $

{ENV, var="YOURVAR"}

, which is the generally supported way to access environment variables. If that doesn't work, then the variable is not in any context that token macro can access it.

sbaumkirchner@conversantmedia.net (JIRA)

unread,
Aug 8, 2016, 2:48:01 PM8/8/16
to jenkinsc...@googlegroups.com

it has never worked using token macro I am injecting the variable using the EnvInject plugin to create the environment variable as seen here:

18:36:56 [EnvInject] - Loading node environment variables.
18:36:56 [EnvInject] - Preparing an environment for the build.
18:36:56 [EnvInject] - Keeping Jenkins system variables.
18:36:56 [EnvInject] - Keeping Jenkins build variables.
18:36:56 [EnvInject] - Executing and processing the following script content:
18:36:56 echo $

{branch}
18:36:56 FOO=`git ls-remote ssh://git@stash:7999/techops/puppet.git origin ${branch}

| cut -f1`
18:36:56
18:36:56
18:36:56 [/tmp] $ /bin/sh -xe /tmp/hudson4110050367620133632.sh
18:36:56 + echo feature-jenkins-slave-swarm-qax
18:36:56 feature-jenkins-slave-swarm-qax
18:36:56 ++ git ls-remote ssh://git@stash:7999/techops/puppet.git origin feature-jenkins-slave-swarm-qax
18:36:56 ++ cut -f1
18:36:56 + FOO=a75e94c868219fdbcd2acab968d8f4a02a3dac7c
18:36:56 [EnvInject] - Script executed successfully.
18:36:56 [EnvInject] - Injecting contributions.

As I can surmise here, my variable is being populated via EnvInject, I can printenv and see FOO with the correct sha. When using the above suggestion I am definitely passing something different to the notifer as i get a 405 response from the stash server.

slide.o.mix@gmail.com (JIRA)

unread,
Aug 8, 2016, 2:50:01 PM8/8/16
to jenkinsc...@googlegroups.com

It's possible that the variable is no longer available once the post build actions are being executed. Did you try the $

{ENV...}

method?

sbaumkirchner@conversantmedia.net (JIRA)

unread,
Aug 8, 2016, 4:20:01 PM8/8/16
to jenkinsc...@googlegroups.com

I did try that method:

$

{ENV, var="$FOO"}

with FOO above being the sha, this is the correct syntax correct?

slide.o.mix@gmail.com (JIRA)

unread,
Aug 8, 2016, 4:25:01 PM8/8/16
to jenkinsc...@googlegroups.com

sbaumkirchner@conversantmedia.net (JIRA)

unread,
Aug 9, 2016, 10:57:01 AM8/9/16
to jenkinsc...@googlegroups.com

So I took your advice, you are right, the FOO variable which is added via EnvInject is not available during the post build steps. I moved the variable creation to a post buildstep shell step and the issue persists. I also changed the variable to as you requested: $

{ENV, var="FOO"}

slide.o.mix@gmail.com (JIRA)

unread,
Aug 9, 2016, 11:06:01 AM8/9/16
to jenkinsc...@googlegroups.com

Environment variables are not available outside the step that creates them, e.g. a shell step can't create an environment variable that will stick around after that step.

sbaumkirchner@conversantmedia.net (JIRA)

unread,
Aug 9, 2016, 11:28:02 AM8/9/16
to jenkinsc...@googlegroups.com

Right, so you're saying an environment var which is created in post build would not be available in post build? or is it plugin specific?

slide.o.mix@gmail.com (JIRA)

unread,
Aug 9, 2016, 11:58:02 AM8/9/16
to jenkinsc...@googlegroups.com

Not available from one post build step to the next. Normally though, anything you create from a normal shell script will not be available outside that specific step (whether build or post-build). This is why EnvInject was created. I am not sure it allows setting environment variables during post-build.

sbaumkirchner@conversantmedia.net (JIRA)

unread,
Aug 9, 2016, 2:46:01 PM8/9/16
to jenkinsc...@googlegroups.com

I've decided to just leave this alone for now. I don't have any more time to work on it. It seems that trying to export the variable at any step the variables are not found. Thank you so much for your help on this Alex. Please close at your leisure.

slide.o.mix@gmail.com (JIRA)

unread,
Aug 9, 2016, 3:15:02 PM8/9/16
to jenkinsc...@googlegroups.com

Sorry it's not working for you. I've been hit by the inability to get environment variables exposed as well.

slide.o.mix@gmail.com (JIRA)

unread,
Aug 9, 2016, 3:15:02 PM8/9/16
to jenkinsc...@googlegroups.com
Alex Earl closed an issue as Not A Defect
 
Change By: Alex Earl
Status: Open Closed
Resolution: Not A Defect
Reply all
Reply to author
Forward
0 new messages