Scheduling parameterized job is possible if there is a default value.
Here I will give an example using Jenkinsfile. Suppose in your pipeline script you have a param testUserName
defined:
pipeline {
parameters {
string(name: 'testUserName', defaultValue: 'defaultTestUser',
description: 'Username to use for test scenarios')
}
stages {
stage('Run tests') {
steps {
sh "mvn verify --batch-mode -Dtest.user=${params.testUserName}"
}
}
}
}
When you press the "Build now" button, the job will run for the first time without asking for params (defaultValue
will be used). After downloading and processing Jenkinsfile within that first run, the button name will change to "Build with Parameters". You click the button and type another user (not the default one defined in Jenkinsfile). The problem is that the value you typed will not persist between job runs. It will always reset to defaultValue
.
To prevent value reset between job runs replace
defaultValue: 'defaultTestUser'
to
defaultValue: params.testUserName ?: 'defaultTestUser'
Now the job will always run with a value previously specified on "Build with Parameters". Found this solution on dev.to