我试图使用azure管道在linux server.Iis上构建一个server.Iis包,在VSTS/Azure管道代码中使用这种方式来增加默认的主标题:未成年人:基于源分支的修补程序?
示例:
如果源分支正在开发:主:小(增量):补丁如果源分支是错误的:主要:小:补丁(增量)如果源分支是主要的:主要(增量):小:补丁
请告诉我你的建议。谢谢
我试图使用azure管道在linux server.Iis上构建一个server.Iis包,在VSTS/Azure管道代码中使用这种方式来增加默认的主标题:未成年人:基于源分支的修补程序?
示例:
如果源分支正在开发:主:小(增量):补丁如果源分支是错误的:主要:小:补丁(增量)如果源分支是主要的:主要(增量):小:补丁
请告诉我你的建议。谢谢
发布于 2022-11-24 06:36:00
您的需求没有内置功能。
在反式管道中有一个DevOps,它可以为每个管道运行自动增加一个变量,但是这个特性在每次运行管道时都会强制增加,不能任意增加或停止。
计数器表达式是用于流水线的,它有两个参数,前缀和种子。种子是基于前缀的。 当第一次设置并运行前缀时,计数器结果将从feed值开始。但是对于后面基于相同前缀的运行,计数器结果将忽略提要值,这将是“最后一次计数器结果+1”。
由于反表达式有这样的限制,我为您编写了一个更自由的设计,以管理主要的、次要的和补丁。
下面是管道的YAML定义。
trigger:
- none
pool:
vmImage: ubuntu-latest
parameters: #The default value of increase major, minor, patch are all false. If you change these to true, the major, minor, patch will auto_increase by default.
- name: increase_major
default: false
type: boolean
values:
- true
- false
- name: increase_minor
default: false
type: boolean
values:
- true
- false
- name: increase_patch
default: false
type: boolean
values:
- true
- false
variables:
- name: Personal_Access_Token
value: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" #Put your personal Access Token here.
- ${{ if eq(parameters.increase_major,false)}}:
- name: increase_major
value: false
- ${{ if eq(parameters.increase_major,true)}}:
- name: increase_major
value: true
- ${{ if eq(parameters.increase_minor,false)}}:
- name: increase_minor
value: false
- ${{ if eq(parameters.increase_minor,true)}}:
- name: increase_minor
value: true
- ${{ if eq(parameters.increase_patch,false)}}:
- name: increase_patch
value: false
- ${{ if eq(parameters.increase_patch,true)}}:
- name: increase_patch
value: true
steps:
#===============================
#Put your pipeline steps here.
#===============================
# The below code will help you auto increase the major, minor, patch.
- task: PythonScript@0
displayName: Change the Major, Minor, Patch.
inputs:
scriptSource: inline
script: |
import json
import requests
#This part is defnition of variables
org_name = "BowmanCP"
project_name = "BowmanCP"
pipeline_definition_id = "376"
personal_access_token = "$(Personal_Access_Token)"
key = 'variables'
increase_major_control = '$(increase_major)'
increase_minor_control = '$(increase_minor)'
increase_patch_control = '$(increase_patch)'
major = "major"
minor = "minor"
patch = "patch"
#This part is logic for auto increase major, minor, patch
def get_value_of_specific_variable(json_content, key, var_name):
data = json.loads(json_content)
return data[key][var_name].get('value')
def auto_increase(json_content, key, var_name):
data = json.loads(json_content)
data[key][var_name]['value'] = str(int(get_value_of_specific_variable(json_content,key,var_name)) + 1)
return data
def get_pipeline_definition(org_name, project_name, pipeline_definition_id, personal_access_token):
url = "https://dev.azure.com/"+org_name+"/"+project_name+"/_apis/build/definitions/"+pipeline_definition_id+"?api-version=6.0"
payload={}
headers = {
'Authorization': 'Basic '+personal_access_token
}
response = requests.request("GET", url, headers=headers, data=payload)
json_content = response.text
return json_content
def update_pipeline_definition(org_name, project_name, pipeline_definition_id, json_content, key, var_name):
json_data = auto_increase(json_content, key, var_name)
url2 = "https://dev.azure.com/"+org_name+"/"+project_name+"/_apis/build/definitions/"+pipeline_definition_id+"?api-version=6.0"
payload2 = json.dumps(json_data)
headers2 = {
'Authorization': 'Basic '+personal_access_token,
'Content-Type': 'application/json'
}
response2 = requests.request("PUT", url2, headers=headers2, data=payload2)
#increase major
if increase_major_control == 'true':
json_data = update_pipeline_definition(org_name, project_name, pipeline_definition_id, get_pipeline_definition(org_name, project_name, pipeline_definition_id, personal_access_token), key, major)
if increase_minor_control == 'true':
json_data = update_pipeline_definition(org_name, project_name, pipeline_definition_id, get_pipeline_definition(org_name, project_name, pipeline_definition_id, personal_access_token), key, minor)
if increase_patch_control == 'true':
json_data = update_pipeline_definition(org_name, project_name, pipeline_definition_id, get_pipeline_definition(org_name, project_name, pipeline_definition_id, personal_access_token), key, patch)运行它时,只需单击复选框即可确定是否增加了minor、patcH和patcH的变量:

变量就在这里:


设计理念:
使用定义-获取REST获取管道信息。
使用代码实现自动增加。
使用定义-更新REST API更改管道定义(管道的变量)。
https://stackoverflow.com/questions/74547746
复制相似问题