GVKun编程网logo

如何在Jenkins多分支管道项目中为职位设置职位属性?(jenkins管道构建)

16

本文的目的是介绍如何在Jenkins多分支管道项目中为职位设置职位属性?的详细情况,特别关注jenkins管道构建的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解如何

本文的目的是介绍如何在Jenkins多分支管道项目中为职位设置职位属性?的详细情况,特别关注jenkins管道构建的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解如何在Jenkins多分支管道项目中为职位设置职位属性?的机会,同时也不会遗漏关于DEVOPS技术实践_09:Jenkins多分支管道、Gitlab合并请求事件未触发Jenkins多分支管道、Jenkins 2多分支管道-如何使用角色策略插件限制分支的可见性/执行?、jenkins 多分支管道中的选项卡更改的知识。

本文目录一览:

如何在Jenkins多分支管道项目中为职位设置职位属性?(jenkins管道构建)

如何在Jenkins多分支管道项目中为职位设置职位属性?(jenkins管道构建)

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

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

我收到错误消息,说自v0.8起,我应该改用options步骤:https ://jenkins.io/doc/book/pipeline/syntax/#declarative-pipeline

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

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

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


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

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

步骤2:使用上游依赖项属性动态填充每个构建,这意味着当某些构建完成时,它们将被启动。

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

答案1

小编典典

步骤1:您可以定义很多属性。以下是您专门寻找的那些:

options{timestamps()}  --> Adds timestamp to console outputtriggers{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语法(在任何作业中)->选择属性:设置作业属性。

声明性管道示例如下:

#!groovypipeline{agent anyoptions{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文件中触发另一个项目。请参阅上面的帖子部分,以使用参数触发该操作。

请让我知道您是否需要更多信息。

DEVOPS技术实践_09:Jenkins多分支管道

DEVOPS技术实践_09:Jenkins多分支管道

简介

多分支的管道是在jenkins2.x中新增的功能 。

多分支管道允许你针对分布式的控制器的每个分支创建一个管道。 下图是对它的一个描述。使用jenkinsfile去创建多分支的管道,jenkinsfile可以存放在代码仓库中。 Jenkinsfile只是定义CI管道的一个脚本。

另外,多分支管道的设计初衷就是当Git仓库中的代码改变时,去自动触发构建。下图是对它的一个描述。

一. 准备工作

(1)在【全局工具配置】中Maven工具已经配置好。
(2)安装了【Pipeline Maven Integration Plugin】
(3)Java工具也需要安装好,由于我们构建是在jenkins master上执行,所以可以跳过此步(因为我们在安装Jenkins时,已经安装好Java)
(4)安装Gitlab插件,本实验使用gitlab做为代码管理

添加gitlab凭据到jenkins中

添加全局凭据

二. 从jenkins中配置在Gitlab服务器的webhooks

 gitlab创建个人访问令牌(personal access token)

2.1 登录到gitlab,点击Settings

2.2 在右侧菜单栏中,点击Access Tokens

2.3 输入令牌名称、到期时间、令牌作用域等选项,点击Create personal access token按钮

2.4 查看生成的个人访问令牌,并保存到安全位置,页面刷新后将无法查看

 

jenkins添加gitlab

 

2.5 添加凭据

 添加后,test测试报错

 

点击高级模式,选择API-levle为v3

升级git版本

[root@node1 ~]# wget https://github.com/git/git/archive/v2.2.1.tar.gz

[root@node1 ~]# tar -xf v2.2.1.tar.gz 

[root@node1 ~]# cd git-2.2.1/

[root@node1 git-2.2.1]# yum install perl-ExtUtils-MakeMaker

[root@node1 git-2.2.1]# yum install zlib-devel 

[root@node1 git-2.2.1]# make configure
GIT_VERSION = 2.2.1
GEN configure

[root@node1 git-2.2.1]# ./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv

[root@node1 git-2.2.1]# make 

[root@node1 git-2.2.1]# make  install

[root@node1 git-2.2.1]# ln -s /usr/local/git/bin/git  /usr/bin/

[root@node1 git-2.2.1]# git --version

git version 2.2.1

问题依然出现,最后排查的过程中发现,复制的不是真正的token,这是坑爹的地方

 

 

 2.6 jenkins查看成功

安装成功

三 创建一个多分支

3.1 编辑jenkinsfile

node (''master'') { 
    checkout scm 
    stage(''Build'') { 
      withMaven(maven: ''M3'') { 
        if (isUnix()) { 
          sh ''mvn -Dmaven.test.failure.ignore clean install package'' 
        }  
        else { 
          bat ''mvn -Dmaven.test.failure.ignore clean install package'' 
        } 
      } 
    }   
    stage(''Results'') { 
      junit ''**/target/surefire-reports/TEST-*.xml'' 
      archive ''target/*.jar'' 
    } 
  } installinstall

提交,开始创建多分枝流水线

3.2 创建多分枝项目

3.3 Trouble Shootting

出现错误:是因为 /usr/libexec/git-core/ 路径没在 PATH 环境变量中。

Started by user darren ning
[Sat Oct 26 14:12:57 EDT 2019] Starting branch indexing...
 > git --version # timeout=10
using GIT_ASKPASS to set credentials 
 > git ls-remote http://192.168.132.132/root/simple-maven-project-with-tests.git # timeout=10
ERROR: [Sat Oct 26 14:12:57 EDT 2019] Could not update folder level actions from source 9d2e73ea-7ee8-4128-a8b2-0d7f20e75599
hudson.plugins.git.GitException: Command "git ls-remote http://192.168.132.132/root/simple-maven-project-with-tests.git" returned status code 128:
stdout: 
stderr: fatal: Unable to find remote helper for ''http''

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2042)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1761)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1666)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1657)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getRemoteReferences(CliGitAPIImpl.java:2877)
    at jenkins.plugins.git.AbstractGitSCMSource.retrieveActions(AbstractGitSCMSource.java:1139)
    at jenkins.scm.api.SCMSource.fetchActions(SCMSource.java:848)
    at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:592)
    at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:277)
    at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:164)
    at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:1026)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
[Sat Oct 26 14:12:57 EDT 2019] Finished branch indexing. Indexing took 19 ms
FATAL: Failed to recompute children of simple-maven-project-with-tests
hudson.plugins.git.GitException: Command "git ls-remote http://192.168.132.132/root/simple-maven-project-with-tests.git" returned status code 128:
stdout: 
stderr: fatal: Unable to find remote helper for ''http''

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2042)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1761)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1666)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1657)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getRemoteReferences(CliGitAPIImpl.java:2877)
    at jenkins.plugins.git.AbstractGitSCMSource.retrieveActions(AbstractGitSCMSource.java:1139)
    at jenkins.scm.api.SCMSource.fetchActions(SCMSource.java:848)
    at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:592)
    at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:277)
    at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:164)
    at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:1026)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE

添加xport PATH=/usr/libexec/git-core:$PATH到/etc/profile里

在此执行

3.4 控制台输出

Started by user darren ning
[Sat Oct 26 14:30:07 EDT 2019] Starting branch indexing...
 > git --version # timeout=10
using GIT_ASKPASS to set credentials 
 > git ls-remote http://192.168.132.132/root/simple-maven-project-with-tests.git # timeout=10
Creating git repository in /root/.jenkins/caches/git-308bd15be61318b6e1166e23433fdd72
 > git init /root/.jenkins/caches/git-308bd15be61318b6e1166e23433fdd72 # timeout=10
Setting origin to http://192.168.132.132/root/simple-maven-project-with-tests.git
 > git config remote.origin.url http://192.168.132.132/root/simple-maven-project-with-tests.git # timeout=10
Fetching & pruning origin...
Listing remote references...
 > git config --get remote.origin.url # timeout=10
 > git --version # timeout=10
using GIT_ASKPASS to set credentials 
 > git ls-remote -h http://192.168.132.132/root/simple-maven-project-with-tests.git # timeout=10
Fetching upstream changes from origin
 > git config --get remote.origin.url # timeout=10
using GIT_ASKPASS to set credentials 
 > git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/* --prune
Checking branches...
  Checking branch master
      ‘Jenkinsfile’ found
    Met criteria
Scheduled build for branch: master
  Checking branch feature
      ‘Jenkinsfile’ found
    Met criteria
Scheduled build for branch: feature
Processed 2 branches
[Sat Oct 26 14:30:08 EDT 2019] Finished branch indexing. Indexing took 1 sec
Finished: SUCCESS

 

 

已经完成

 

Gitlab合并请求事件未触发Jenkins多分支管道

Gitlab合并请求事件未触发Jenkins多分支管道

我正在尝试使用GitLab Webhook在合并请求事件上触发Jenkins多分支管道作业。

在测试Webhook时,我收到以下消息:

挂钩成功执行,但返回HTTP 409

当我设置不同的GitLab Webhook时,例如标签推送事件,它可以工作。

Jenkins多分支管道不支持GitLab合并请求事件Webhook吗?我想念什么吗?

如果不支持,是否有人有解决方法?

谢谢!

Jenkins 2多分支管道-如何使用角色策略插件限制分支的可见性/执行?

Jenkins 2多分支管道-如何使用角色策略插件限制分支的可见性/执行?

我在具有两个分支的项目中使用多分支管道:开发和掌握。这将创建两个子项目,每个分支一个。

App_Pipeline     |---master     |---develop

我已经设置了角色策略插件,以根据分配的角色来控制作业/管道的授权(可见性)。

项目角色

  • 管理员 :使用正则表达式App_.*
  • 开发人员 :使用正则表达式App_.*

在我目前的角色下,两种类型的用户都可以看到超级项目(App_Pipeline),并且可以执行两个子项目。

关键是我希望一些用户(开发人员)能够查看和运行开发子项目,而另一些用户(经理)能够查看和运行两个子项目(主项目和开发项目)。

我还没有找到配置它的方法,知道如何实现它吗?

更新: 这是问题的整个上下文。

我正在使用多分支管道来扫描整个Bitbucket项目,这给了我:

ORGANIZATION   Repo1     |---master     |---develop   Repo2     |---master     |---develop   Poc-repo1     |---master     |---develop   Poc-repo2     |---master     |---develop

我需要支持以下情况:

  1. 一些用户只能读取和构建带有Poc-前缀的项目。应该看不到其他项目。
  2. 其他用户可以阅读所有项目,但只能建立开发分支
  3. 最后,其他人可以阅读并构建所有项目

答案1

小编典典

它受两级安全结构的支持,例如:

rol1 ".*holaArtifactoryMultibranch.*" --> readrol2 ".*holaArtifactoryMultibranch\/master.*" --> build

现在,您可以将用户/组关联到rol1和rol2

更新:

如果您有一个中间文件夹,我明白了:

rol1    "^FOLDER$"   --> readrol2    "^FOLDER\/holaArtifactoryMultibranch.*$"--> read

您会看到holaArtifactoryMultibranch文件夹,但看不到其他文件夹。

jenkins 多分支管道中的选项卡更改

jenkins 多分支管道中的选项卡更改

如何解决jenkins 多分支管道中的选项卡更改?

我构建了多分支管道,并且我有每晚运行构建的更改选项卡 enter image description here

enter image description here

知道如何禁用它吗? 我更改 jenkins 文件以跳过所有阶段,如果它来自更改但它使用了旧的 jenkins 文件

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

关于如何在Jenkins多分支管道项目中为职位设置职位属性?jenkins管道构建的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于DEVOPS技术实践_09:Jenkins多分支管道、Gitlab合并请求事件未触发Jenkins多分支管道、Jenkins 2多分支管道-如何使用角色策略插件限制分支的可见性/执行?、jenkins 多分支管道中的选项卡更改的相关知识,请在本站寻找。

本文标签: