当前位置:网站首页>[Jenkins] shell script calls Jenkins API interface

[Jenkins] shell script calls Jenkins API interface

2022-06-22 10:38:00 bulabula2022

# Use list for What the loop is going to run job name
for variable in  job1 job2 job3
do
    # Get the next build number
    job_number=`curl --silent http://ip:port/job/$variable/api/json --user account:password |jq --raw-output '.nextBuildNumber'`
    # perform job
    curl -n -X POST http://ip:port/job/$variable/buildWithParameters --user --user account:password --data cp_branch='git Branch '
    # Inquire about job The state can execute in cycles at most 5 Time                
    for i in `seq 1 5` 
      do
         # Query interval ,60s, Start the next job Maximum interval 5 minute
         sleep 60
         # Get current job Running results
         ##job_result=$(curl --silent http://ip:port/job/$variable/lastBuild/api/json --user account:password |jq --raw-output '.result')
         job_result=`curl --silent http://ip:port/job/$variable/$job_number/api/json --user account:password |jq --raw-output '.result'`
        
         echo "================= The first $i Detection current job name :${variable},job Number :$job_number,job Running state : $job_result ====================================="
         if [[ $job_result = "SUCCESS" ]];then
           echo "=================job:$variable Build complete , Run next ==================="
         break
         elif [[ $job_result = "FAILURE" ]] || [[ $job_result = "ABORTED" ]];then
           echo "=================job:$variable Build failed , Run next ==================="
         break
         elif [[ $i = 5 ]] && [[ $job_result = "null" ]];then
           echo "=================job:$variable Build more than 5 minute , Not waiting. , Run the next... Directly job ==================="
         else [[ $job_result = "null" ]]
           echo "job_$variable In the building ......"
         fi

     done
done

原网站

版权声明
本文为[bulabula2022]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221012488005.html

随机推荐