I am using a pipeline in a jenkinsfile and I am not sure how to properly link the job in Jenkins and the pipeline.
I defined parameters in my jenkinsfile (some with def
This problem can be solved by adding a special parameter to avoid default values being override. Here is the sample code.
if (!params.__INIT__) { // this value will be true once parameters get initialized
properties([ parameters([
string(name: 'SOURCE_URL', trim: true),
string(name: 'TARGET_URL', trim: true),
string(name: 'DEPLOY_URL', trim: true),
credentials(name: 'DEPLOY_KEY', required: true ),
string(name: 'BUILD_NODE', trim: true),
booleanParam(name: '__INIT__', defaultValue: true, description: "Uncheck this field in configuration page and run this job once if you want to re init parameter."),
]) ])
return // exit
}
// Your task stars from here
By doing this way, the parameters won't be initialized again next time because __INIT__
has been set to true
. On the other hand, if you update your script and change some parameters, you can just run the job by unchecking the __INIT__
field.