Jenkins Pipeline高级用法-ShareLibrary

时间:2023-03-09 13:13:53
Jenkins Pipeline高级用法-ShareLibrary

1.Github配置

1.1 上传jenkinsfile到github

https://github.com/zeyangli/ShareLibrary-jenkins.git

Jenkins Pipeline高级用法-ShareLibrary

2.Jenkins配置

2.1 添加gitlab凭据

凭据管理-->凭据-->系统 -->添加凭据

Jenkins Pipeline高级用法-ShareLibrary

2.2 ShareLibrary配置

系统管理-->系统设置-->Global Pipeline librarys

Jenkins Pipeline高级用法-ShareLibrary

2.3 安装插件

saltstack
ansicolor

3.发布配置

3.1 master安装salt-master salt-api

yum -y install salt salt-master salt-api
vim /etc/salt/master #添加以下内容 salt 2015.5.10

rest_cherrypy:
port: 9000
disable_ssl: True

external_auth:
pam:
saltapi:
- .*
- '@wheel'
- '@runner

file_roots:
base:
- /srv/salt

service salt-master start

service salt-apo start

useradd saltapi

passwd saltapi  #123456

3.2 应用服务器部署salt-minion

yum -y install salt-minion
echo "master: 10.10.1.1" > /etc/salt/minion

3.2 测试

salt-key -L
salt-key -a xxxxxxx
salt xxx test.ping

curl http://127.0.0.1:9000/login -d username='saltapi' -d password='123456' -d eauth='pam'
{"return": [{"perms": [".*", "@wheel", "@runner"], "start": 1552134573.2227211, "token": "fa089bbd2c641a3136b2fb3bf305ab5111c54343", "expire": 1552177773.2227211, "user": "saltapi", "eauth": "pam"}]}[root@VM_7_14_centos auth]#

FAQ

1.[更新Git版本]centos6 默认yum装的git 版本1.7.1 太低了导致出错。

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
wget https://github.com/git/git/archive/v2.3.0.zip
unzip v2.3.0.zip
cd git-2.3.
make prefix=/usr/local/git all
vim /etc/profile
export PATH=/usr/local/git/bin:$PATH
source /etc/profile

2.[重新安装Git,项目构建出错]

Started by user admin
java.io.IOException: error=, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:)
at java.lang.ProcessImpl.start(ProcessImpl.java:)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:)
Caused: java.io.IOException: Cannot run program "git" (in directory "/var/lib/jenkins/caches/git-c25d623df84deea801370f6c265e18c9"): error=, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:)
at hudson.Proc$LocalProc.<init>(Proc.java:)
at hudson.Proc$LocalProc.<init>(Proc.java:)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:)
at hudson.Launcher$ProcStarter.start(Launcher.java:)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:)
Caused: hudson.plugins.git.GitException: Error performing command: git init /var/lib/jenkins/caches/git-c25d623df84deea801370f6c265e18c9
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$.execute(CliGitAPIImpl.java:)
Caused: hudson.plugins.git.GitException: Could not init /var/lib/jenkins/caches/git-c25d623df84deea801370f6c265e18c9
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$.execute(CliGitAPIImpl.java:)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.init(CliGitAPIImpl.java:)
at hudson.plugins.git.GitAPI.init(GitAPI.java:)
at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:)
at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:)
at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:)
at hudson.model.ResourceController.execute(ResourceController.java:)
at hudson.model.Executor.run(Executor.java:)
Finished: FAILURE 解决方法: 系统设置,全局工具设置,更改git的位置。

3.没有安装saltstack插件

java.lang.NoSuchMethodError: No such DSL method 'salt' found among steps