We have got a parameterized Jenkins pipeline. One parameter of our parameter list is a Git commit hash. Once in a while, this parameter is not set (intentional behavior).
pipeline {
...
parameters {
string(defaultValue: '', description: 'Hash', name: 'CommitHash');
}
}
Now, we want to implement a caching mechanism. This mechanism requires the parameter (hash) to be set, as future builds need to access this parameter. However, this contradicts the idea of the optional parameter. The simplest solution, namely, defining the variable as mandatory is no option. For this reason, we have implemented the following solutions:
Since I am not a huge fan of these solutions, I want to set the parameter during runtime. However, this approach only sets the parameter in my local job. Since the parameter was not set initially, the build information accessed from a future build will contain an unset parameter. Is there any way to set the parameter during runtime, so that it is saved also in the overall parameter list when accessed by another job.
Modifying parameters makes your code more difficult to read. If you need to persist some information use env
. Values you assign are available in future builds
currentBuild.previousBuild.buildVariables.SOME_VAR