jenkins 2.x Remote access API的CURL实现
1.1、创建任务
curl -v -X POST {JENKINS_INDEX}/createItem?name={JOB_NAME} --data-binary "@/path/to/config.xml" -H "Content-Type: text/xml" --user {USER_NAME}:{PASSWORD}

示例:

curl -v -X POST http://localhost:8080/createItem?name=testProject --data-binary "@/home/leleliu008/config.xml" -H "Content-Type: text/xml" --user liufupin:123456
1.2、启用任务
curl -v -X POST {JENKINS_INDEX}/job/{JOB_NAME}/enable --user {USER_NAME}:{PASSWORD}

示例:

curl -v -X POST http://localhost:8080/job/testProject/enable --user liufupin:123456
1.3、禁用任务
curl -v -X POST {JENKINS_INDEX}/job/{JOB_NAME}/disable --user {USER_NAME}:{PASSWORD}

示例:

curl -v -X POST http://localhost:8080/job/testProject/disable --user liufupin:123456
1.4、删除任务
curl -v -X POST {JENKINS_INDEX}/job/{JOB_NAME}/doDelete --user {USER_NAME}:{PASSWORD}

示例:

curl -v -X POST http://localhost:8080/job/testProject/doDelete --user liufupin:123456
1.5、构建任务
curl -v -X POST {JENKINS_INDEX}/job/{JOB_NAME}/build --user {USER_NAME}:{PASSWORD}

示例:

curl -v -X POST http://localhost:8080/job/testProject/doDelete --user liufupin:123456
1.6、触发任务的SCM检查
curl -v -X POST {JENKINS_INDEX}/job/{JOB_NAME}/polling --user {USER_NAME}:{PASSWORD}

示例:

curl -v -X POST http://localhost:8080/job/testProject/polling --user liufupin:123456
1.7、获取任务的描述
curl -v -X GET {JENKINS_INDEX}/job/{JOB_NAME}/description --user {USER_NAME}:{PASSWORD}

示例:

curl -v -X GET http://localhost:8080/job/testProject/description --user liufupin:123456
1.8、更新任务的描述
curl -v -X POST {JENKINS_INDEX}/job/{JOB_NAME}/description description={DESCRIPTION} --user {USER_NAME}:{PASSWORD}

示例:

curl -v -X POST http://localhost:8080/job/testProject/description description=我是更新后的描述 --user liufupin:123456
1.9、获取任务的配置
curl -v -X GET {JENKINS_INDEX}/job/{JOB_NAME}/config.xml --user {USER_NAME}:{PASSWORD}

示例:

curl -v -X GET http://localhost:8080/job/testProject/config.xml --user liufupin:123456
1.10、更新任务的配置
curl -v -X POST {JENKINS_INDEX}/job/{JOB_NAME}/config.xml --data-binary "@/path/to/config.xml" -H "Content-Type: text/xml" --user {USER_NAME}:{PASSWORD}

示例:

curl -v -X POST http://localhost:8080/job/testProject/config.xml --data-binary "@/home/leleliu008/config.xml" -H "Content-Type: text/xml" --user liufupin:123456