jenkins 使用 curl 触发 jenkins 编译 & 自动从ftp上下载更新程序库
来源:互联网 发布:淘宝香火符咒西极飞飞 编辑:程序博客网 时间:2024/06/04 20:02
关于在 git hooks 中使用 curl 触发编译:
假设项目名字叫 Two, 项目的 Authentication Token 为 ABC(同上).
方法1 . 在 Manage Jenkins -> Configure Global Security 中去掉 “Prevent Cross Site Request Forgery exploits” 选项,然后就可以使用下述命令触发编译了:
curl --user 'USER:PASSWD' -X POST "http://localhost:8080/job/Two/build?token=ABC"// orcurl --user 'USER:PASSWD' -X POST "http://localhost:8080/job/Two/build" --data token=ABC--data delay=0sec// 或者不使用密码,使用 user API token: 点击用户名-> Configure 显示 API Tokencurl -u guowei:173ey74ac39d284u610c83c6fd32847e -X POST http://localhost:8080/job/Two/build?token=ABC
方法2 . 如果选中了 “Prevent Cross Site Request Forgery exploits” 选项,则需要先获得一个 CSRF protection token,然后再将这个 token 作为HTTP请求的 header 发送过去:
curl -u guowei:38e2427ac39d5a5f810c83c6fd39ee80 http://localhost:8080/crumbIssuer/api/json// 你将获得一个返回json数据,例如:{"_class":"hudson.security.csrf.DefaultCrumbIssuer","crumb":"39v8495d439i36cbd93b928461u1fe15","crumbRequestField":"Jenkins-Crumb"}// 然后再这样触发编译:curl -u guowei:38e2427ac39d5a5f810c83c6fd39ee80 -H "Jenkins-Crumb:39v8495d439i36cbd93b928461u1fe15" -X POST http://localhost:8080/job/Two/build?token=ABC
如果觉得麻烦,可以写成这样一个脚本:
#!/bin/bashCRUMB=$(curl -s 'http://guowei:38e2427ac39d5a5f810c83c6fd39ee80 @localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')curl -u guowei:38e2427ac39d5a5f810c83c6fd39ee80 -H "$CRUMB" -X POST "http://localhost:8080/job/Two/build" --data token=ABC --data delay=0sec
see link: http://zdk.github.io/jenkins-remote-build-trigger-with-bitbucket-hook
方法3 . 在新建 Job 的时候选择 Poll SCM, Schedule 可以为空. 使用这个方式只有在 git server 端代码有更新时才会触发build,没有更新不会触发。
在 git server 的 post-receive hook 中插入以下代码:
curl http://localhost:8080/git/notifyCommit?url=ssh://git@xxx.git&branches=master
在 Job 的界面中会出现一个 Git Polling Log 的选项,点进去可以看到日志信息。
see link: https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin
lftp 自动从服务器上下载更新程序包:
#!/bin/bashcd ~USER=guoweiPASSWD=xxxxxxIP=192.168.1.13REMOTEDIR="abc/efg"FILENAME=$(lftp -c "open -u $USER,$PASSWD $IP; cd $REMOTEDIR && cls myfile*")if [ "$FILENAME" != "" ]; thenlftp $USER:$PASSWD@$IP << EOFcd $REMOTEDIRmget -E myfile* quitEOFecho "$FILENAME download successfully, extract? (y/n)"read ans# now check if $x is "y"if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then tar -xvf $FILENAME echo "update ok!"else echo "update aborted!"fielse echo "Cat not login to server: $USER@$IP"fi
0 0
- jenkins 使用 curl 触发 jenkins 编译 & 自动从ftp上下载更新程序库
- Jenkins+ftp 使用过程
- 使用Jenkins自动编译部署web应用
- CI搭建三:jenkins新建项目代码更新自动编译
- Jenkins自动编译常见问题汇总(持续更新)
- 持续集成:Jmeter+Maven+Jenkins自动化框架搭建(四):GitLab代码更新触发Jenkins自动构建
- jenkins构建下游任务不能自动触发
- Gitlab自动触发Jenkins构建打包
- jenkins下自动编译操作
- jenkins自动编译maven项目
- 【Android】使用Jenkins+Gradle+FTP,实现自动打包,自动上传文件至FTP
- linux shell 脚本自动从配置远程ftp服务上下载更新文件
- Jenkins在Mac上的使用,关于Xcode编译问题
- 使用jenkins做自动测试
- 使用Jenkins自动部署博客
- Centos上安装使用Jenkins
- jenkins远程触发构建
- jenkins构建触发
- java.lang.NoSuchFieldError
- linux+mysql数据导出的一般过程
- 超链接CSS样式
- Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
- MSDN控件样式和模版
- jenkins 使用 curl 触发 jenkins 编译 & 自动从ftp上下载更新程序库
- Sybase数据库表备份
- Linux mount挂载共享文件
- java笔记--day09--多态(二)
- ALSA声卡笔记1---ALSA驱动框架
- docker 常用命令(持续更新)
- iOS 通讯录操作 删除联系人 以及联系人多个号码 如何删除其中一个号码
- [iOS]百分比编码
- 选项卡实现(使用this)