Promote build with Jenkins API

会有一股神秘感。 提交于 2020-02-28 09:34:07

问题


Given a Jenkins build job with different promotion jobs (i.e., that promote builds to different environments), how can one trigger a specific promotion job for a specific build using the Jenkins API?


回答1:


Combined answers from different sources to come up with this:

$Username = "Username"
$APItoken = '12345'
$Credential = "$($Username):$($APItoken)"
$EncodedCredential = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($Credential))
$BasicAuthValue = "Basic $EncodedCredential"
$Headers = @{
                Authorization = $BasicAuthValue
            }

Write-Output "Promoting build $LatestBuildNumber to Environment..."

Invoke-WebRequest -URI "http://jenkins.prd.company.com/job/jobname/buildnumber/promotion/forcePromotion?name=PromoteToEnvironment" -Headers $Headers



回答2:


I know this is an old thread, but just to help the community.

Shell Solution using CURL:

user_name="jenkins_user"
    user_token="token" 
    promotion_name="Test_Promote"
    jenkins_url="http://build-server.com"
    JOB_NAME="job_name"
    JOB_NO="job-no"

    url="--silent -u $user_name:$user_token $jenkins_url/job/$JOB_NAME/$JOB_NO/promotion/forcePromotion?name=$promotion_name"
    curl $url

How to generate jenkins user token: https://jenkins.io/blog/2018/07/02/new-api-token-system/



来源:https://stackoverflow.com/questions/43311953/promote-build-with-jenkins-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!