首页 > 解决方案 > Jenkins 管道 Cron Auto Scheduler 作业在调度程序/计时器运行后用 Jenkins UI 中的默认值覆盖用户输入的值

问题描述

我正在创建 Dataflow Jenkins 自动调度程序作业,用户可以在其中输入运行数据流作业所需的一些参数,并且应该能够安排作业。用户可以在需要时通过更改 Jenkins UI/控制台中的 cron 值来安排作业。

该作业按预期工作,它在指定时间安排作业,并获取用户在 Jenkins 控制台的输入文本字段中提供的任何值,并使用用户输入的值触发。但是在调度程序/计时器运行并完成作业后,后续作业运行,它会在调度程序/计时器运行后用 Jenkins UI 中的默认值覆盖用户输入的值。“Jenkins 管道 Cron 自动调度程序作业在调度程序/计时器运行后用 Jenkins UI 中的默认值覆盖用户输入的值”

有没有人遇到过类似的问题或对上述查询有解决方案?感谢您在这件事上的帮助。

这是我的 Jenkins groovy 脚本文件代码

//Dataflow Jenkins pipeline auto scheduler job
properties([
    parameters([
        choice(name: 'jarType', choices: ['snapshot','release'], description: 'Select the JarType to execute the files'),

        string(name: 'hour', description: 'The hour of the day in 24 hour in (0-23) format', defaultValue: '14'),
        string(name: 'dayInMonth', description: 'DOM: The day in the month in (1–31) format', defaultValue: '*'),
        string(name: 'theMonth', description: 'MONTH: The month in (1–12) format', defaultValue: '*'),
        string(name: 'dayInWeek', description: 'DOW: The day in the week in (0–7) format', defaultValue: '*'),

        string(name: 'jobName', description: 'Please enter jobName for the Dataflow job', defaultValue: 'test'),
        string(name: 'project', description: 'Please enter project for the Dataflow job', defaultValue: 'test'),
    ]),

    pipelineTriggers(createPipelineTriggers())
])

//below is the scheduling part
def createPipelineTriggers() {
    echo "H ${params.hour} ${params.dayInMonth} ${params.theMonth} ${params.dayInWeek} ${params.jobName} ${params.project}"
    if (env.BRANCH_NAME == 'develop') {
        // return [cron("H ${params.hour} ${params.dayInMonth} ${params.theMonth} ${params.dayInWeek} %jobName=${params.jobName}; project=${params.project}")]
        return [cron("H ${params.hour} ${params.dayInMonth} ${params.theMonth} ${params.dayInWeek}")]

    }
    return []
}

node("test-pod") {
    container('test-container') {

        stage("Checkout Scm"){
            checkout scm
        }

        stage("Download ${params.jarType} CI jar from Nexus") {
          echo "${params.jarType}"
          //****
        }

        stage("Download xxxx and xxxx from Nexus") {
            //**
        }

        stage("Running dataflow job") {
            rootDir = pwd()
            try {
                sh "java -jar ${params.application}.jar \\\n" + "--runner=DataflowRunner --jobName=${params.jobName} --project=${params.project} 

            } catch (Exception e) {
                echo "dataflow job Failed"
            }

        }

    }
}

标签: jenkinscronjenkins-pipeline

解决方案


推荐阅读