jenkins-api应用
#需求:获取指定view下作业并执行
http://192.168.10.14:8080/view/test/api/json
作业pipeline
pipeline {
agent {
node {
label 'master01'
}
}
options {
disableConcurrentBuilds()
}
stages {
stage('Build Jobs By View') {
steps {
sh '''
set -e
JENKINS_URL="https://jenkins.meng.com"
VIEW_NAME=$VIEW_NAME
USERNAME="meng"
TOKEN="mengtoken"
view_info=$(curl -s -u "$USERNAME:$TOKEN" "$JENKINS_URL/view/$VIEW_NAME/api/json")
job_names=$(echo "$view_info" | jq -r '.jobs[].name')
# crumb=$(curl -s -u "$USERNAME:$TOKEN" "$JENKINS_URL/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)")
for job_name in $job_names; do
curl -u "$USERNAME:$TOKEN" -X POST "$JENKINS_URL/job/$job_name/job/$VIEW_NAME/build"
done
'''
}
}
}
}
标签:USERNAME,URL,job,api,应用,jenkins,JENKINS,view
From: https://blog.csdn.net/lisanmengmeng/article/details/142908975