简介

多分支的管道是在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 :: EDT ] Starting branch indexing...
> git --version # timeout=
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 :: EDT ] Could not update folder level actions from source 9d2e73ea-7ee8--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 :
stdout:
stderr: fatal: Unable to find remote helper for 'http' at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getRemoteReferences(CliGitAPIImpl.java:)
at jenkins.plugins.git.AbstractGitSCMSource.retrieveActions(AbstractGitSCMSource.java:)
at jenkins.scm.api.SCMSource.fetchActions(SCMSource.java:)
at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:)
at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:)
at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:)
at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:)
at hudson.model.ResourceController.execute(ResourceController.java:)
at hudson.model.Executor.run(Executor.java:)
[Sat Oct :: EDT ] Finished branch indexing. Indexing took 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 :
stdout:
stderr: fatal: Unable to find remote helper for 'http' at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getRemoteReferences(CliGitAPIImpl.java:)
at jenkins.plugins.git.AbstractGitSCMSource.retrieveActions(AbstractGitSCMSource.java:)
at jenkins.scm.api.SCMSource.fetchActions(SCMSource.java:)
at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:)
at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:)
at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:)
at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:)
at hudson.model.ResourceController.execute(ResourceController.java:)
at hudson.model.Executor.run(Executor.java:)
Finished: FAILURE

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

在此执行

3.4 控制台输出

Started by user darren ning
[Sat Oct :: EDT ] Starting branch indexing...
> git --version # timeout=
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=
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=
> git --version # timeout=
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=
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

已经完成

DEVOPS技术实践_09:Jenkins多分支管道的更多相关文章

  1. DEVOPS技术实践_07:Jenkins 管道工作

    一 简介 由于在公司构建很多工作,都是使用的maven工作构建的,这种构建方式很大缺点就是所有的工作都需要一步一步的配置,当项目较多,需求变动时,需要很大的精力去修改配置,很费劲 Pipeline即为 ...

  2. DEVOPS技术实践_18:Jenkins的Pinpeline对于参数的使用

    因为最近使用Pipeline声明式语法构建项目,但是最近项目的参数设置较多,特地的来学习一下关于参数的调用和测试,主要式从一个大神那里学习的,结尾回贴上大神的博客链接 1 构建一个pipeline项目 ...

  3. DEVOPS技术实践_17:Jenkins使用扩展邮件功能发送邮件

    一 环境准备 1.1 安装插件Email Extension 系统管理-管理插件-安装Email Extension插件 1.2 配置 配置jenkins邮箱的全局配置:系统管理-系统设置-完成邮箱配 ...

  4. DEVOPS技术实践_11:Jenkins集成Sonar

    前言 前面已经有介绍sonar的安装,简单应用,下面在简答的研究一下sonar和jenkins集成的简单使用,对于sonar的安装不做介绍 一 sonar的简单介绍 持续检查避免了低质量的代码,比如S ...

  5. DEVOPS技术实践_02:jenkins自动构建项目

    一.用户名密码错误 打开jenkins发现用户名密码错误,解决 1.1 找到config.xml文件 [root@jenkins-master ~]# ll -a drwxr-xr-x. root r ...

  6. DEVOPS技术实践_01:jenkins集成平台

    一.准备环境 准备三台机器 角色 IP地址 用户名 密码 jenkins-master   172.25.254.130    admin   meiyoumima gitlab 172.25.254 ...

  7. DEVOPS技术实践_13:使用Jenkins持续传送设计-CD基础

    1. 分支策略 持续集成中使用的分支策略包括以下三个: The master branch The integration branch The feature branch 而CD只在Integra ...

  8. DEVOPS技术实践_12:创建持续集成的管道

    持续集成不仅包含了Jenkins或者相关其它的CI工具,也包含了包含代码如何控制,采用的什么分支策略等.不同的组织可能采用不同的类型的策略来完成CI,策略类型和项目的类型的有很大的关系. 一 分支策略 ...

  9. DEVOPS技术实践_08:声明式管道语法

    简介 前面简单的做了管道的实验,看了一下的它的效果 声明式管道是Groovy语法中的一个更简单和结构化的语法.下面主要学习明式管道语法. 一 声明式管道的基本结构 以上节的代码为例 node { de ...

随机推荐

  1. Android EditText____TextchangedListener

    今天在做APP的时候有个需求: EditText 动态监听内容变化如果长度为6时(就是看是不是验证码) 判断是否正确 正确就跳到下一个Activity,但是在Activity.finish()的时候, ...

  2. 02docker简单使用和配置(网络、存储和Hub)

    四:网络 1:命名容器 在各种docker命令中,可以通过名字中找到对应的容器.之前创建的容器都是由docker自动命名的,可以在docker  run中,通过--name参数指定容器的名字.比如: ...

  3. 阿里靠什么支撑 EB 级计算力?

    作者 关涛 阿里云智能事业群 研究员 导读:MaxCompute 是阿里EB级计算平台,经过十年磨砺,它成为阿里巴巴集团数据中台的计算核心和阿里云大数据的基础服务.去年MaxCompute 做了哪些工 ...

  4. 洛谷P1510 精卫填海

    //01背包 求背包内物品价值超过某一定值时的最小体积 #include<bits/stdc++.h> using namespace std; ; ; int n,v_tot,w_tot ...

  5. top 9 Cloud Computing Failures

    top 9 Cloud Computing Failures Outages, hacks, bad weather, human error and other factors have led t ...

  6. 检查进程启动情况,开始时间、启动时间、启动进程数、进程数是否正确、PID

    #!/bin/sh bin=$(cd ``;pwd) cd ${bin} ### 定义检查函数 chk(){ programName=$ correctNum=$ programSubName=$ # ...

  7. Laravel5.2 发送邮件(smtp方式最简单的讲解!)-邮件部分

    https://blog.csdn.net/wulove52/article/details/71172842 Laravel集成了SwiftMailer库进行邮件发送,邮件配置文件位于config/ ...

  8. BERT-Pytorch demo初探

    https://zhuanlan.zhihu.com/p/50773178 概述 本文基于 pytorch-pretrained-BERT(huggingface)版本的复现,探究如下几个问题: py ...

  9. 开源CMS比较

    PHP-CMS的发展方向:简单,易用,美观  http://www.php-cms.cn/ 看点1,服务器一键安装,鼠标点点就搞定:输入数据库参数,在服务器上点一个按钮就完成全部的安装.简单配置一下网 ...

  10. 洛谷P1288 取数游戏II 题解 博弈论

    题目链接:https://www.luogu.org/problem/P1288 首先,如果你的一边的边是 \(0\) ,那么你肯定走另一边. 那么你走另一边绝对不能让这条边有剩余,因为这条边有剩余的 ...