如何在Jenkins多分支管道项目中设置职位的职位属性? [英] How to set job properties for jobs within a Jenkins multi-branch pipeline project?

查看:97
本文介绍了如何在Jenkins多分支管道项目中设置职位的职位属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道在Jenkinsfile中设置作业属性(特别是构建触发器)的正确方法吗? (声明性管道脚本,在多分支管道作业中).

为清楚起见,我需要为多分支项目中的基础作业设置特定的构建触发器.我可以在GUI中配置总体多分支项目的触发器.

For clarity I need to set specific build triggers for underlying jobs in a multibranch project. The triggers for the overarching multibranch project I can configure in the GUI.

这里列出了尝试过的方法: Jenkins多分支管道并指定上游项目

Have tried methods listed here: Jenkins multi-branch pipeline and specifying upstream projects

Jenkins:在上游变更时触发多分支管道

如何使用Jenkins Pipeline属性步骤?

我收到错误消息,说从v0.8开始,我应该改用options步骤: https://jenkins.io/doc/book/book/pipeline/syntax/#声明性管道

I get errors saying that since v0.8 I should be using the options step instead: https://jenkins.io/doc/book/pipeline/syntax/#declarative-pipeline

但是我看不到那里列出的任何步骤,这些步骤允许在options指令内设置构建触发器.

But I can't see any steps listed there that allow be to set build triggers within the options directive.

服务器上的每个分支作业文件夹中都有一个config.xml,但是我认为当我再次运行该作业时,由于它们位于多分支作业下,因此将被覆盖.

There is a config.xml in each of the branched job folders on the server, but I think this will be overwritten when I run the job again, as they sit under the multi branch job.

还有一个选项可以将不同的属性传递到不同的分支(分支例外),但我看到的唯一选择是禁止SCM提交.

There is also an option to pass different properties into different branches (make exceptions for branches) but the only option I see there is to suppress SCM commits.

我的总体目标是尝试创建一个Jenkins文件,该文件动态地允许多分支项目中的所有基础作业由其相关的上游构建触发.

My overall aim with this is to try and make a single Jenkinsfile that dynamically allows all the underlying jobs in the multibranch project to be triggered by their dependent upstream builds.

第1步:弄清楚如何设置属性:)

Step 1: Work out how to set properties at all :)

第2步:使用上游依赖项属性动态填充每个内部版本,这意味着当某些内部版本完成时,它们就会启动.

Step 2: Populate each build dynamically with the upstream dependency properties, meaning they get kicked off when certain builds complete.

问题仅涉及第1步,而第2步正是我要达到的目标.

Question concerns step 1 only, step 2 is just where I'm trying to get to.

推荐答案

步骤1:您可以定义很多属性.下面列出了您正在寻找的特定对象:

Step 1: There are lot of properties that you could define. The ones that you are specifically looking for are listed below:

options{timestamps()}  --> Adds timestamp to console output
triggers{pollSCM('H/15 * * * *')} --> Polling SCM 
triggers{cron('H/15 * * * *')} --> Trigger build every 15 minutes. Similarly you can set the build trigger to any specific time to build it periodically.

此外,您可以找到可使用每个作业中可用的管道语法"中的属性选项定义的所有属性.请导航至PIpeline语法(在任何作业中)->选择属性:设置作业属性.

Moreover, you can find all the properties that could be defined using the properties options in 'Pipeline Syntax' that is made available in every job. Please naviagte to PIpeline syntax(in any of the jobs) --> select proeprties: set job proerpties.

示例性声明管道可能如下:

A sample declarative pipeline could be as follows:

#!groovy
pipeline{
agent any
options{timestamps()}
triggers{pollSCM('H/15 * * * *')}
parameters{
 ..........
}
environment{
............
}
stages{
stage{
steps{
..............
}
}
}
post{
always{
build job: '/foldername/job1', parameters: [string(name: 'parameter1', value: "${params.parameter1}")] , propagate: false
}
}
}

步骤2:您可以使用"build"命令从Jenkins文件中触发另一个项目.请参阅上面的帖子部分,以使用参数触发该操作.

step 2: You can trigger another project from within the Jenkins file using the 'build' command. Refer the post section above to trigger the same with parameters.

如果您需要更多信息,请告诉我.

Kindly let me know if you would require further information.

这篇关于如何在Jenkins多分支管道项目中设置职位的职位属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆