1. 概述
远程触发, 是指不直接在jenkins上点击构建, 而是通过脚本或其他方式触发jenkins构建任务, 打通jenkins与外部程序的通信
2. 配置
远程触发选项: Trigger builds remotely
Enable this option if you would like to trigger new builds by accessing a special predefined URL (convenient for scripts).
One typical example for this feature would be to trigger new build from the source control system’s hook script, when somebody has just committed a change into the repository, or from a script that parses your source control email notifications.
3. 演示
3.1. 说明
远程触发是通过API方式拉起
- jenkins项目url: JENKINS_URL/job/P101/build?token=TOKEN_NAME (TOKEN_NAME自行配置)
- 可选参数: &cause=Cause+Text, 记录构建原因
3.2. shell脚本
-u admin:admin 指定jenkins用户/密码, 如果是匿名用户, 可能出现鉴权失败
[root@localhost ~]# cat trigger.sh
#!/bin/bash
echo "Work Done !!!"
echo "Trigger jenkins job ..."
curl -u admin:admin "http://192.168.197.128:8080/job/P101/build?token=abcdefg1234567890&cause=Cause+RemoteSignal"
exit 0
3.3. 执行
sh trigger.sh