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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Danny Trunk
Hello everyone,

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

jobs:
  - 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' {
                      path('Jenkinsfile')
                    }
                  }
                }
                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.

Danny.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/WRZAIQ.I9W7CPAM6YSS%40gmail.com.
Reply | Threaded
Open this post in threaded view
|

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

Reinhold Füreder

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:

 

properties([

    parameters([

        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?

 

Thanks,

               Reinhold

 

 

From: [hidden email] <[hidden email]> On Behalf Of Danny Trunk
Sent: Freitag, 16. Oktober 2020 18:43
To: [hidden email]
Subject: [JCasC] job parameters lost when re-starting docker container / reloading existing configuration

 

Hello everyone,

 

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

 

jobs:

  - 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' {

                      path('Jenkinsfile')

                    }

                  }

                }

                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.

 

Danny.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/WRZAIQ.I9W7CPAM6YSS%40gmail.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/VI1PR01MB663850482ACC88A69738BB34F7849%40VI1PR01MB6638.eurprd01.prod.exchangelabs.com.
Reply | Threaded
Open this post in threaded view
|

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

Björn Pedersen
Yes, 

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?

Björn

r.fuereder schrieb am Freitag, 19. Februar 2021 um 07:57:23 UTC+1:

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:

 

properties([

    parameters([

        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?

 

Thanks,

               Reinhold

 

 

From: [hidden email] <[hidden email]> On Behalf Of Danny Trunk
Sent: Freitag, 16. Oktober 2020 18:43
To: [hidden email]
Subject: [JCasC] job parameters lost when re-starting docker container / reloading existing configuration

 

Hello everyone,

 

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

 

jobs:

  - 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' {

                      path('Jenkinsfile')

                    }

                  }

                }

                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.

 

Danny.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/WRZAIQ.I9W7CPAM6YSS%40gmail.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/8754a01a-5807-450a-a0eb-2b3d368acef6n%40googlegroups.com.