jenkinsci / build-name-setter-plugin

Build Name Setter Plugin for Jenkins CI
https://plugins.jenkins.io/build-name-setter/
MIT License
34 stars 51 forks source link

After upgrading plugin from v1.7.1 to v2.0 causes MacroEvaluationException #39

Closed J00MZ closed 5 years ago

J00MZ commented 5 years ago

Encountered different behavior when using variable BUILD_USER_ID as job name

in v1.7.1 job continued with error message Unrecognized macro 'BUILD_USER_ID' but did not fail
in v2.0 job fails

EDIT: Issue occurs only when setting the name on job start.
So it's possible to implement a workaround by setting the name only at job completion.

v1.7.1

08:30:18 Set build name.
08:30:18 Unrecognized macro 'BUILD_USER_ID' in '#5722-5.6.70.202@${BUILD_USER_ID}'
08:30:18 [BuildAndPackage - Branch for PROD] $ /bin/sh -xe /tmp/jenkins74161814099455574.sh

v 2.0

09:07:18 ERROR: Processing failed due to a bug in the code. Please report this to the issue tracker (https://jenkins.io/redirect/report-an-issue).
09:07:18 java.lang.IllegalArgumentException: org.jenkinsci.plugins.tokenmacro.MacroEvaluationException: Unrecognized macro 'BUILD_USER_ID' in '#5726-5.6.70.204@${BUILD_USER_ID}'
09:07:18    at org.jenkinsci.plugins.buildnamesetter.Executor.evaluateMacro(Executor.java:56)
09:07:18    at org.jenkinsci.plugins.buildnamesetter.Executor.setName(Executor.java:28)
09:07:18    at org.jenkinsci.plugins.buildnamesetter.BuildNameSetter.setUp(BuildNameSetter.java:84)
09:07:18    at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:667)
09:07:18    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
09:07:18    at hudson.model.Run.execute(Run.java:1818)
09:07:18    at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
09:07:18    at hudson.model.ResourceController.execute(ResourceController.java:97)
09:07:18    at hudson.model.Executor.run(Executor.java:429)
09:07:18 Caused by: org.jenkinsci.plugins.tokenmacro.MacroEvaluationException: Unrecognized macro 'BUILD_USER_ID' in '#5726-5.6.70.204@${BUILD_USER_ID}'

Jenkins Version: 2.174

damianszczepanik commented 5 years ago

Why you ate trying to pass invalid variable to the plugin?

J00MZ commented 5 years ago

@damianszczepanik It's a valid variable.

I'm currently using a workaround of this issue by setting the plug-in to update only after the build completed.

Then the variable BUILD_USER_ID resolves just fine to the users username.

This issue occurs only when setting the name on job start.

damianszczepanik commented 5 years ago

So you are trying to use undefined variable at the beginning of building process as it becomed defined later.

J00MZ commented 5 years ago

@damianszczepanik I'm using this plug-in to set BUILD_USER_ID variable.

Are you saying that plug-in sets the variable after the Build Setter does?

damianszczepanik commented 5 years ago

Based on the log from previous version it looks like this is true.

slmjy commented 5 years ago

It's common to use an environment variable that will be set during the build later in the build name. And the macro syntax works without specifying ${ENV,var="envvarname"}, just ${envvarname}. Now I've changed it to ${ENV,var="envvarname"}, but it is not updated when the variable appears. So the only option is revert to 1.7.1

damianszczepanik commented 5 years ago

Revert to older version. Looks like there is regression which happens when thus plugin is used with other.

damianszczepanik commented 5 years ago

Fixed, will release asap

damianszczepanik commented 5 years ago

Released