[JCasC] job parameters lost when re-starting docker container / reloading existing configuration

Skip to first unread message

Danny Trunk

Oct 16, 2020, 12:55:28 PM10/16/20
to jenkins...@googlegroups.com
Hello everyone,

I've set up a container with jenkins.yaml file in $JENKINS_HOME which is loading a parameterized pipeline job:

  - script: >
      pipelineJob('lineage') {
        definition {
          cpsScm {
            scriptPath 'Jenkinsfile'
            scm {
              git {
                configure { git ->
                  git / 'extensions' / 'hudson.plugins.git.extensions.impl.SparseCheckoutPaths' / 'sparseCheckoutPaths' {
                    'hudson.plugins.git.extensions.impl.SparseCheckoutPath' {
                extensions {}
                remote {

In order to retrieve the parameters defined in the Jenkinsfile it needs to be initially run.
There's a known issue which described that behaviour: https://issues.jenkins-ci.org/browse/JENKINS-41929

But now, everytime i restart the container or reload existing configuration through UI parameters are gone again and my workaround to abort the first build doesn't work anymore because it checks for the build number 1:

script {
if ('1'.equals(env.BUILD_NUMBER) && currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause') != null) {
currentBuild.displayName = 'Parameter loading'
currentBuild.description = 'Please restart pipeline'
currentBuild.result = 'ABORTED'

error 'Stopping initial manually triggered build as we only want to get the parameters'

Any ideas on how I can extend my workaround or better how to avoid removing existing job parameters when reloading existing configuration?
I don't know if this can be considered a bug or an enhancement request for JCasC to not remove those job parameters.
Any help is appreciated.


Reinhold Füreder

Feb 19, 2021, 1:57:23 AM2/19/21
to jenkins...@googlegroups.com

Hi Danny et al,


I think, I just stumbled over the same problem:

  • parameterized pipeline + Jenkins Docker container restart + JCasC + JobDSL (that is re-generating the parameterized scripted pipeline – pipeline from SCM -- during Jenkins startup via “j.j.plugin.JenkinsJobManagement#createOrUpdateConfig: createOrUpdateConfig for ...”)



One possible workaround – that might be OK if there are very few affected parameterized pipelines, or the parameterization is fairly stable, or there are just very few different paramaterizations – seems to be duplicating the parameterization into the JobDSL specification of the pipeline, for example:


  • In the pipeline code:




        string(name: 'targetHost', defaultValue: 'my.host.com', description: 'IP/Hostname of target server', trim: true)




  • In the JobDSL code:


pipelineJob(" My pipeline JobName") {

  // Workaround for https://issues.jenkins.io/browse/JENKINS-43758?focusedCommentId=380158&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-380158

  parameters {

    stringParam('targetHost', 'my.host.com', 'IP/Hostname of target server')


  definition {

    cpsScm {




Are there any updates on this problem?

Or are there open Jenkins (plugin) issues that really address this problem? Or should we file a new one specific for this problem? (If so, I am not even sure for which Jenkins plugin, to be perfectly honest.)

Or is there a better workaround?




You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/WRZAIQ.I9W7CPAM6YSS%40gmail.com.

Björn Pedersen

Feb 22, 2021, 4:37:34 AM2/22/21
to Jenkins Users

this seems like a general chicken-and-egg problem when specifying parameter-config in the Jenkinsfile. It also affects any updated Jenkinsfile that adds a new parameter/changes a  parameter , as these changes only take effect *after * the job is started. The only really working solution would be to run the Jenkinsfile twice (once for setup, e.g. parameters) and then to do the real work. But then what to do if the Jenkinsfile e.g. depends on a branch parameter? Which jenkinsfile should be used?


Reply all
Reply to author
0 new messages