-
Bug
-
Resolution: Not A Defect
-
Minor
-
Powered by SuggestiMate
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
[JENKINS-37238] Problems expanding variables created outside the Jenkins build
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
The plugin IS compatible with earlier versions. It's just still under test, which is why it is released as a beta.
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
no the above errors are from the 1.9 version of token-macro. I'm using jenkins version: 1.655 as well.
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.
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.
It's possible that the variable is no longer available once the post build actions are being executed. Did you try the ${ENV...} method?
I did try that method:
${ENV, var="$FOO"}
with FOO above being the sha, this is the correct syntax correct?
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"}
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.
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?
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.
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.
It looks like you are using the beta release, which means this is not critical.