鉴于Jenkins构建作业具有不同的促销作业(即,将构建促进到不同的环境),如何使用Jenkins API触发特定构建的特定促销作业?
答案 0 :(得分:2)
来自不同来源的综合答案提出了这个问题:
$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
答案 1 :(得分:2)
我知道这是一个老话题,但这只是为了帮助社区。 p>
使用CURL的Shell解决方案:
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
如何生成詹金斯用户令牌:https://jenkins.io/blog/2018/07/02/new-api-token-system/