gpt4 book ai didi

Trying to kick off a scheduled Jenkins job from another job(尝试从另一个作业启动计划的Jenkins作业)

转载 作者:bug小助手 更新时间:2023-10-25 14:02:12 27 4
gpt4 key购买 nike



I'm using a declarative pipeline to kick off an existing job on a schedule (with different parameters) and therefore have something similar to :-

我使用声明性管道按计划(使用不同的参数)启动现有作业,因此具有类似以下内容:


pipeline any
triggers {
cron('H 6 8 * *')
}
stages {
stage('Remove old AMIs from account 1') {
steps {
script {
b = build(job: 'another job',
parameters: [string(name: 'ACCOUNT', value: 'account1')
// some other parameters
}
}
}
stage('Remove old AMIs from account 2')
// ... removed for brevity
}

However this has the effect of running the initial job once when you kick it off, and then once again at the scheduled time (once a month on the 8th).

但是,这样做的效果是在启动初始作业时运行一次,然后在计划的时间(每月8日运行一次)运行一次。


What I'd like to do is to schedule the target job ('another job') to run at a specific time, not the initial job above.

我想做的是将目标作业(“另一个作业”)安排在特定时间运行,而不是上面的初始作业。


I've tried various combinations, and scanned search results + the docs, but I can't find anything for this particular case. I'm guessing I need something like triggers at the same level as job / parameters within the b = build?

我尝试了各种组合,扫描了搜索结果和文档,但我找不到任何针对这个特定案例的东西。我猜我需要与b=Build中的作业/参数处于同一级别的触发器?


更多回答
优秀答案推荐

you can achieve what you want using the Parameterized Scheduler Plugin.

The plugin supports setting parameters in the build schedule, thus allowing you to schedule your parameterized build to run with different configurations at different times according to the parameters.

您可以使用参数化的Scheduler插件实现您想要的功能。该插件支持设置构建时间表中的参数,从而允许您根据参数在不同的时间以不同的配置运行您的参数化构建。


For example consider the following pipeline:

例如,考虑以下管道:


pipeline {
agent any
parameters {
string(name: 'OPTION', defaultValue: 'manual')
}
triggers {
parameterizedCron('''
0 8 * * * %OPTION=autoMorning
0 20 * * * %PLANET=autoEvening
''')

stages {
stage('Remove old AMIs from account 1') {
when {
environment name: 'OPTION', value: 'manual'
}
steps {
build(job: 'JobA', parameters: ...)
}
}
stage('Remove old AMIs from account 1') {
when {
environment name: 'OPTION', value: 'autoMorning'
}
steps {
build(job: 'JobB', parameters: ...)
}
}
stage('Remove old AMIs from account 1') {
when {
environment name: 'OPTION', value: 'autoEvening'
}
steps {
build(job: 'JobB', parameters: ...)
}
}
}
}

In this pipeline -> when you run it manually JobA will be executed, every day a 8AM JobB will be executed and very day a 8PM JobC will be executed.

So each job can have its own schedule regardless of the execution type.

在这个管道中->当您手动运行它时,JobA将被执行,每天上午8点的JobB将被执行,每天晚上8点的JobC将被执行。因此,无论执行类型如何,每个作业都可以有自己的计划。


In your case it can be something like:

在您的情况下,它可能是这样的:


pipeline{
agent any
triggers {
// Set a customized schedule for the 'another job'
parameterizedCron('0 8 * * * %OPTION=another')
}
stages {
stage('Remove old AMIs from account 1') {
when {
environment name: 'OPTION', value: 'another'
}
steps {
script {
b = build(job: 'another job',
parameters: [string(name: 'ACCOUNT', value: 'account1') // some other parameters
}
}
}
stage('Remove old AMIs from account 2')
// ... removed for brevity
}
}

So you have a custom schedule for you job which is not affected from manual executions.

因此,您的作业有一个不受手动执行影响的自定义计划。


更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com