简体   繁体   English

Jenkins:运行作业后参数从管道作业中消失

[英]Jenkins: Parameters disappear from pipeline job after running the job

I've been trying to construct multiple jobs from a list and everything seems to be working as expected.我一直在尝试从列表中构建多个工作,并且一切似乎都按预期工作。 But as soon as I execute the first build (which works correctly) the parameters in the job disappears.但是,一旦我执行第一个构建(正常工作),作业中的参数就会消失。 This is how I've constructed the pipelineJob for the project.这就是我为项目构建pipelineJob的方式。

import javaposse.jobdsl.dsl.DslFactory

def repositories = [
        [
                id         : 'jenkins-test',
                name       : 'jenkins-test',
                displayName: 'Jenkins Test',
                repo       : 'ssh://<JENKINS_BASE_URL>/<PROJECT_SLUG>/jenkins-test.git'
        ]
]

DslFactory dslFactory = this as DslFactory

repositories.each { repository ->
    pipelineJob(repository.name) {
        parameters {
            stringParam("BRANCH", "master", "")
        }
        logRotator{
            numToKeep(30)
        }
        authenticationToken('<TOKEN_MATCHES_WITH_THE_BITBUCKET_POST_RECEIVE_HOOK>')
        displayName(repository.displayName)
        description("Builds deploy pipelines for ${repository.displayName}")
        definition {
            cpsScm {
                scm {
                    git {
                        branch('${BRANCH}')
                        remote {
                            url(repository.repo)
                            credentials('<CREDENTIAL_NAME>')
                        }
                        extensions {
                            localBranch('${BRANCH}')
                            wipeOutWorkspace()
                            cloneOptions {
                                noTags(false)
                            }
                        }
                    }
                    scriptPath('Jenkinsfile)
                }
            }
        }

    }
}

After running the above script, all the required jobs are created successfully.运行上述脚本后,所有需要的作业都已成功创建。 But then once I build any job, the parameters disappear.但是一旦我建立任何工作,参数就会消失。

参数消失

After that when I run the seed job again, the job starts showing the parameter.之后,当我再次运行种子作业时,作业开始显示参数。 I'm having a hard time figuring out where the problem is.我很难弄清楚问题出在哪里。

I've tried many things but nothing works.我尝试了很多东西,但没有任何效果。 Would appreciate any help.将不胜感激任何帮助。 Thanks.谢谢。

This comment helped me to figure out similar issue with my.groovy file: I called parameters property twice (one at the node start and then tried to set other parameters in if block), so the latter has overwritten the initial parameters. 此评论帮助我找出与 my.groovy 文件类似的问题:我两次调用parameters属性(一次在节点启动时,然后尝试在if块中设置其他参数),因此后者覆盖了初始参数。

BTW, as per the comments in the linked ticket, it is an issue with both scripted and declarative pipelines.顺便说一句,根据链接票证中的评论,这是脚本和声明性管道的问题。

Fixed by providing all job parameters in each parameters call - for the case with if s.通过在每个参数调用中提供所有作业参数来修复- 对于if s 的情况。

Though I don't see repeated calls in the code you've provided, please check the full groovy files for your jobs and add all parameters to all parameters {} blocks.虽然我没有在您提供的代码中看到重复调用,但请检查您的作业的完整 groovy 文件并将所有参数添加到所有parameters {}块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM