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 ...”)
>       - Problem is (again and again) the first run of pipeline after 
>       Jenkins Docker container restart
>          - Note: I think I am OK with the (missing parameterization) 
>          problem in any very first pipeline run ever, or after changing the 
> pipeline 
>          parameterization
>          - => JCasC or JobDSL might need to address this issue, I 
>          guess/think?
>       - I personally think that these open Jenkins bugs/issues are not 
>       necessarily correctly specified, or let’s say they or their title might 
> be 
>       too generic?
>          - https://issues.jenkins-ci.org/browse/JENKINS-41929 “*Offer 
>          "Build with Parameters" on first build when declarative Jenkinsfile 
> found*
>          ”
>             - => No, my problem is also for scripted
>          - https://issues.jenkins.io/browse/JENKINS-43758 “*Parameters 
>          disappear from pipeline job after running the job*”
>             - => No, normally parameters stay; it is only gone after 
>             Jenkins Docker container restart
>             - Actually the comment by Falko Modler in 
>             
> https://issues.jenkins.io/browse/JENKINS-43758?focusedCommentId=380158&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-380158
>  
>             describes it perfectly, I think!
>          
>  
>
>  
>
> 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 <http://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:* jenkins...@googlegroups.com <jenkins...@googlegroups.com> *On 
> Behalf Of *Danny Trunk
> *Sent:* Freitag, 16. Oktober 2020 18:43
> *To:* jenkins...@googlegroups.com
> *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 {
>
>                   url '
> https://github.com/dtrunk90/jenkins-lineage-docker.git'
>
>                 }
>
>               }
>
>             }
>
>           }
>
>         }
>
>       }
>
>  
>
> 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 jenkinsci-use...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jenkinsci-users/WRZAIQ.I9W7CPAM6YSS%40gmail.com
>  
> <https://groups.google.com/d/msgid/jenkinsci-users/WRZAIQ.I9W7CPAM6YSS%40gmail.com?utm_medium=email&utm_source=footer>
> .
>

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

Reply via email to