脚本化管道中的参数化调度程序

时间:2019-05-22 14:40:35

标签: jenkins-pipeline

我从declerativ管道切换到脚本管道。一切正常,只有参数化调度程序插件会出现问题。如果我有一个触发器,则可以正常工作,并且可以安排管道。如果我添加另一个触发器,则仅第二个触发器起作用。可能是语法问题,但我尝试的所有方法均无效。有什么想法吗?

properties([ 
    parameters([            
        booleanParam (defaultValue: true, description: 'test', name: 'test')
    ]),
    pipelineTriggers([   
        parameterizedCron('15 20 * * * test=true'),
        parameterizedCron('05 20 * * * test=false')
    ])      
])//properties

1 个答案:

答案 0 :(得分:0)

根据official documentation,您的语法有误,您丢失了%。您也可以使用一个多行parameterizedCron

pipeline {
    agent any
    parameters {
      string(name: 'PLANET', defaultValue: 'Earth', description: 'Which planet are we on?')
      string(name: 'GREETING', defaultValue: 'Hello', description: 'How shall we greet?')
    }
    triggers {
        cron('* * * * *')
        parameterizedCron('''
# leave spaces where you want them around the parameters. They'll be trimmed.
# we let the build run with the default name
*/2 * * * * %GREETING=Hola;PLANET=Pluto
*/3 * * * * %PLANET=Mars
        ''')
    }
    stages {
        stage('Example') {
            steps {
                echo "${GREETING} ${PLANET}"
                script { currentBuild.description = "${GREETING} ${PLANET}" }
            }
        }
    }
}

所以您的情况应该是

properties([ 
    parameters([            
        booleanParam (defaultValue: true, description: 'test', name: 'test')
    ]),
    pipelineTriggers([   
        parameterizedCron('''
             15 20 * * * %test=true
             05 20 * * * %test=false''')
    ])      
])//properties

还请注意,这里有this open issue,它表示要为您的触发器注册脚本,它至少需要手动运行两次。

相关问题