Jenkins - 从Jenkins master 本地加载Global Pipeline Libraries

从目前Jenkins的设计看来,这是不可能的。
但是我们可以变通一下,初始化本地 git 存储库并将其用作SCM来实现需求,而不需要任何远程主机git remote service

如何配置? ->

  • Jenkins 新建一个文件夹(Folder)
  • 找到 Pipeline Libraries -- > Add, 按照如下图方式配置Libraries
    image.png

注意:Project Repository 为Jenkins master 本地文件目录, 例如“/opt/identity/Jenkins2Library”

  • 保存后回到文件夹(Folder)界面

  • Jenkins master host 服务器端配置 CentOS-7为例
[root@ Jenkins2Library]# pwd
/opt/identity/Jenkins2Library
[root@ Jenkins2Library]# ll
total 16
-rw-------. 1 root root  101 Aug  2 07:24 Jenkinsfile
drwx------. 2 root root 4096 Aug  2 07:24 Jenkinsfiles
-rw-------. 1 root root   17 Aug  2 07:24 README.md
drwx------. 3 root root   17 Aug  2 07:24 src
drwx------. 2 root root 4096 Aug  2 07:24 vars
  • init a git repo 初始化git
git init
git add .
git commit -m "init"

如果遇到要配置email 和name 的情况,就按照提示配置一下
git config --global user.email "[email protected]"
git config --global user.name "Your Name"

  • 检查git init 是否生效:
[root@ Jenkins2Library]# git status
# On branch master
nothing to commit, working directory clean
[root@ JenkinsPipeline]# /usr/bin/git ls-remote -h /opt/identity/Jenkins2Library
4a1433d16c5b493c5221ebcd8eef1fb3d93ea88e        refs/heads/master
  • 把目录owner 改为Jenkins(重要,否则不工作)
chown jenkins:jenkins -R JenkinsPipeline

  • 回到Jenkins文件夹下,创建一个pipeline job

    image.png

  • 配置pipeline:


    image.png
  • 保存配置然后运行


Attempting to resolve master from remote references...
 > /usr/bin/git --version # timeout=10
 > /usr/bin/git ls-remote -h /opt/identity/Jenkins2Library # timeout=10
Found match: refs/heads/master revision 316758891406c3dc332b8ee9edc10063f9556ef5
No credentials specified
 > /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > /usr/bin/git config remote.origin.url /opt/identity/Jenkins2Library # timeout=10
Fetching without tags
Fetching upstream changes from /opt/identity/Jenkins2Library
 > /usr/bin/git --version # timeout=10
 > /usr/bin/git fetch --no-tags --progress /opt/identity/Jenkins2Library +refs/heads/*:refs/remotes/origin/*
Checking out Revision 316758891406c3dc332b8ee9edc10063f9556ef5 (master)
 > /usr/bin/git config core.sparsecheckout # timeout=10
 > /usr/bin/git checkout -f 316758891406c3dc332b8ee9edc10063f9556ef5
Commit message: "init"
 > /usr/bin/git rev-list --no-walk 316758891406c3dc332b8ee9edc10063f9556ef5 # timeout=10

[Pipeline] Start of Pipeline[](/2/console#) 

Works, Have Fun!! :)

你可能感兴趣的:(Jenkins - 从Jenkins master 本地加载Global Pipeline Libraries)