Jenkins+GitHub实现自动化构建
一开始使用官网下载的包出现了permission denied错误,猜测是由于安装的时候默认安装在共享文件夹,在构建的过程中会有包的移动的情况,因此重新brew install jenkins安装。
1、brew install jenkins安装
2、直接输入jenkins启动,该启动可利用ctrl+c终止jenkins
3、配置常见插件,包括maven、git相关的
4、一开始是配置这样的webhooks不成功,
HTTP ERROR 404
Problem accessing /project/{project_name}. Reason:
Not Found
Powered by Jetty:// 9.4.z-SNAPSHOT
控制台打印如下警告
警告: New Stapler routing rules result in the URL "/projects/{project_name}" no longer being allowed. If you consider it safe to use, add the following to the whitelist: "method jenkins.model.Jenkins getProjects". Learn more: https://jenkins.io/redirect/stapler-routing
通过官网查询得知在新版本的jenkins已经取消这样的访问
Build when a change is pushed to GitLab. GitLab webhook URL: http://127.0.0.1:8080/project/{project_name}
4、于是选择Trigger builds remotely (e.g., from scripts)
5、http://{jenkins_url}:{port}/job/{project_name}/build?token={Authentication Token},在浏览器可以触发构建,在postman中(get成功,post失败,在jenkins的全局安全配置去掉Prevent Cross Site Request Forgery exploits的勾选,get成功,post成功)
6、如果在访问http://{jenkins_url}:{port}/job/{project_name}/build?token={Authentication Token}的时候跳到登录页面,可以在jenkins的全局安全设置里面Access Control——Authorization选中任何用户可以做任何事(如果考虑到安全因素建议配置别的安全条件)
7、GitHub进入项目——settings——webhooks——add webhook——Payload URL填入http://{jenkins_url}:{port}/job/{project_name}/build?token={Authentication Token}保存即可触发调用
8、浏览器可以触发、postman可以触发,但github触发一直报Couldn't connect to server,后面发现是由于局域网导致,通过brew cask install ngrok,开通外网映射解决
9、构建成功后,可以自动发布到tomcat,进入到jenkins的Post-build Actions——add post-build-action,需要在本地tomcat增加user配置apache-tomcat-7.0.69/conf/tomcat-users.xml,配置用户名密码到Credentials,tomcat url是启动tomcat的url