Using the env.BRANCH_NAME
variable accessible in the Jenkinsfile outside of the pipeline{}
block, I have set up a variable used to conditionally set the node used to build the git branch. I would like to also access the name of the developer who committed the change, but I do not know how to access it.
I need a variable assigned before the pipeline block to assign to pipeline { agent { label selected_agent }}
. If I attempt to use a method call instead of a variable there, the Java parser complains:
java.lang.ClassCastException: org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.Label.label expects class java.lang.String but received class org.jenkinsci.plugins.pipeline.modeldefinition.ClosureModelTranslator
I cannot run code inside the pipeline block before the agent block to define the variable, and the agent block has to be the first part of the pipeline declaration.
If I could run bash commands, I could access the author's name, and in fact I do use it at the end of the Jenkinsfile to pull the git committer's name for the status email, but if I attempt to use sh() before the pipeline block I get this error:
Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
I am not sure what else to try. Does anyone have a suggestion?