Jenkins Pipeline高级用法-ShareLibrary

 

1.Github配置

1.1 上传jenkinsfile到github

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

 

2.Jenkins配置

2.1 添加gitlab凭据

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

 

2.2 ShareLibrary配置

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

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.0
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=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
Caused: java.io.IOException: Cannot run program "git" (in directory "/var/lib/jenkins/caches/git-c25d623df84deea801370f6c265e18c9"): error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at hudson.Proc$LocalProc.<init>(Proc.java:249)
    at hudson.Proc$LocalProc.<init>(Proc.java:218)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:936)
    at hudson.Launcher$ProcStarter.start(Launcher.java:455)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2038)
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:2049)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2010)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2006)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1638)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:811)
Caused: hudson.plugins.git.GitException: Could not init /var/lib/jenkins/caches/git-c25d623df84deea801370f6c265e18c9
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:813)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.init(CliGitAPIImpl.java:286)
    at hudson.plugins.git.GitAPI.init(GitAPI.java:217)
    at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:324)
    at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:198)
    at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:174)
    at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:108)
    at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:67)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:293)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE

解决方法: 系统设置,全局工具设置,更改git的位置。

 

3.没有安装saltstack插件

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

 

posted @ 2019-03-09 20:03  Zeyangli  阅读(5326)  评论(0编辑  收藏  举报