我有一个jenkinsfile,我在其中创建一个分支,但仅在下次我要跳过该阶段时才需要创建一次,但应该运行其他阶段。例如:-第一次运行 stage(“创建发行分支”),但是当我再次运行管道时,它不应运行,而其余阶段应运行。 我该怎么办?
def config = "Release"
pipeline
{
agent none
parameters {
string(name: 'SPRINT_NUMBER', defaultValue: '9959')
string(name: 'RELEASE_NUMBER', defaultValue: '60')
string(name: 'CYCLE_NAME', defaultValue: '60')
string(name: 'S_DATE', defaultValue: '4/Dec/19')
string(name: 'E_DATE', defaultValue: '30/Dec/20')
}
stages
{
stage('Windows')
{
agent
{
node
{
label "csharp.bbn.is.avb.com"
customWorkspace "E:/Jenkins/ws/${env.BRANCH_NAME}".take(30)
}
}
stages
{
stage("Creating Release Branch")
{
steps
{
echo "Hello ${env:SPRINT_NUMBER}"
powershell label: '', script: '''
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("Authorization", "Basic aTAyMzIy")
$body = "{ `"name`": `"release/testbranch_${env:SPRINT_NUMBER}`", `"startPoint`": `"refs/heads/master`" }"
$response = Invoke-RestMethod \'https://bitbucket.it.avb.com/projects/LAB/repos/lab/branches\' -Method \'POST\' -Headers $headers -Body $body
$response | ConvertTo-Json'''
}
}
}
stage("Creating Release Version"){
def msg = powershell(returnStdout: true, script: '''$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("Authorization", "Basic aml6Wnlr")
$headers.Add("Cookie", "JSESSIONID=FF25875CE609245560DC756E214C35BF; atlassian.xsrf.token=B5DX-9S26-JQRI-OYXM_5cc3f5fe2cc_lin; sto-id=BFM")
$body = "{`"description`": `"test`",`"name`": `"Release-${env:RELEASE_NUMBER}`",`"userReleaseDate`": `"5/Jul/2020`",`"project`": `"LAB`",`"archived`": false,`"released`": true}"
$response = Invoke-RestMethod \'https://jira.it.avb.com/rest/api/latest/version\' -Method \'POST\' -Headers $headers -Body $body
$response | ConvertTo-Json''')
echo msg
writeFile file: 'script.json', text: msg
def vid = readJSON file: 'E:/Jenkins/workspace/2799/script.json'
versionid = "${vid.id}"
}
script
{
env.VID = versionid
}
stage("SOME STAGE"){
def msgg = powershell(returnStdout: true, script: '''$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("Accept", "application/json")
$headers.Add("Authorization", "Basic lreEA5NDy")
$headers.Add("Cookie", "JSESSIONID=D2F4667829139C7FAFF013B856E8803F; atlassian.xsrf.token=B5DX-9S26-JQRI-OYXM_9235435063_lin; sto-id=BHE")
$body = "{
`n `"clonedCycleId`": `"`",
`n `"name`": `"Official`",
`n `"build`": `"`",
`n `"environment`": `"`",
`n `"description`": `"Create cycle with sprint`",
`n `"startDate`": `"${env:S_DATE}`",
`n `"endDate`": `"${env:E_DATE}`",
`n `"projectId`": `"129`",
`n `"versionId`": `"${env:VID}`"
`n}"
$response = Invoke-RestMethod \'https://jira.it.avb.com/rest/zapi/latest/cycle\' -Method \'POST\' -Headers $headers -Body $body
$response | ConvertTo-Json''')
writeFile file: 'script2.json', text: msgg
def cid = readJSON file: 'E:/Jenkins/workspace/2799/script2.json'
cycleid = "${cid.id}"
}
}
}
}