Tasks / Задачи - https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/?view=azure-pipelines
Expressions / Выражения - https://docs.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops
$url = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)$env:SYSTEM_TEAMPROJECTID/_apis/Release/definitions/$($env:RELEASE_DEFINITIONID)?api-version=5.0" Write-Host "URL: $url" $pipeline = Invoke-RestMethod -Uri $url -Headers @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" } Write-Host "Pipeline = $($pipeline | ConvertTo-Json -Depth 100)" # Update an existing variable named v1030 to its new value 1035 $pipeline.variables.v1030.value = "1035" ####****************** update the modified object ************************** $json = @($pipeline) | ConvertTo-Json -Depth 99 $updatedef = Invoke-RestMethod -Uri $url -Method Put -Body $json -ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} write-host "==========================================================" Write-host "The value of Varialbe 'v1030' is updated to" $updatedef.variables.v1030.value write-host "=========================================================="
Job 1, powershell:
Write-Host "##vso[task.setvariable variable=testvar;]testvalue"
Job 2, powershell:
Write-Host "Using testvar: $($env:testvar) = $(testvar)"
https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash
https://medium.com/microsoftazure/how-to-pass-variables-in-azure-pipelines-yaml-tasks-5c81c5d31763
Установить build версию в YAML:
version: $[format('{0:yyMM}.{0:dd}.{1}.{2}', pipeline.startTime, variables['system.pullRequest.pullRequestId'], counter(format('{0:yyyyMMdd}-{1}', pipeline.startTime, variables['Build.SourceBranchName']), 1))]
Пример присвоения: 2108.07.2424.1
Обновить build версию:
echo "##vso[build.updatebuildnumber]$version"
Write-Host "##vso[build.updatebuildnumber]$version"
Обновить release версию:
echo "##vso[release.updatereleasename]$version"
Write-Host "##vso[release.updatereleasename]$version"
Команды ведения журнала - https://learn.microsoft.com/ru-ru/azure/devops/pipelines/scripts/logging-commands
Добавить tag на commit из pipeline:
steps: - checkout: self fetchDepth: 1 clean: true persistCredentials: true
- script: | git tag $(tag) git push --tags workingDirectory: $(Build.SourcesDirectory) displayName: 'git tag $(tag)'
Добавить тэг migrations на pipeline
Write-Host "##vso[build.addbuildtag]migrations"
https://piotr.gg/dev-ops/add-tag-to-you-build-in-azure-devops.html
Для доступа pipeline к репозиториям в других проектах, в проекте с этим pipeline:
https://github.com/microsoftdocs/azure-devops-docs/issues/11939
Пример добавления префикса к версии сборки в зависимости от ветки:
name: $(version) variables: ${{ if contains(variables['Build.SourceBranch'],'/pull/') }}: version: $[format('{0}.{1}',variables['system.pullRequest.pullRequestId'],counter(variables['system.pullRequest.pullRequestId'], 0))] ${{ if in(variables['Build.SourceBranchName'], 'main','master') }}: version: $[format('{0}.{1:yyMM}.{1:dd}.{2}', variables['majorVersion'], pipeline.startTime, counter(format('{0:yyyyMMdd}-{1}', pipeline.startTime, variables['Build.SourceBranchName']), 1))] ${{ if and(not(contains(variables['Build.SourceBranch'], '/pull/')),notIn(variables['Build.SourceBranchName'], 'main','master')) }}: version: $[format('{0}.{1:yyMM}.{1:dd}.{2}-{3}', variables['majorVersion'], pipeline.startTime, counter(format('{0:yyyyMMdd}-{1}', pipeline.startTime, variables['Build.SourceBranchName']), 1), variables['Build.SourceBranchName'])]
Checkout без --tags (в конце обязательно поставить job «git unset»):
https://github.com/microsoft/azure-pipelines-agent/blob/master/docs/design/percentEncoding.md
Кодировать токен в base64 (добавить префикс pat:):
TOKEN64=$(echo -n "pat:${TOKEN}" | base64)
Клонировать репозиторий с помощью токена:
git -c http.extraheader="AUTHORIZATION: basic ${TOKEN64}" clone https://dev.azure.com/ORGNAME/PROJECT/_git/REPOSITORY
Azure DevOps → Organization Settings → Agent pools → Add pool
Azure DevOps → User settings → Personal Access Tokens → New Token → Agent Pools: Read & Manage
docker build -t azureagent . docker run -e AZP_URL=https://organization.visualstudio.com -e AZP_AGENT_NAME=dockeragent -e AZP_POOL=Docker -e AZP_TOKEN=secret-token --rm -d azureagent
https://docs.microsoft.com/Ru-Ru/Azure/Devops/pipelines/agents/docker?view=azure-devops
https://github.com/microsoft/azure-devops-tls12 - скрипт для «смягчения» последствий перехода на TLS 1.2
https://stackoverflow.com/questions/70929356/azure-pipelines-local-agent-failing-to-connect-with-ssl-error
https://devblogs.microsoft.com/visualstudio/azure-devops-requires-tls-1-2-on-all-connections-including-visual-studio/
Решение: Включить передачу токена в checkout pipeline: persistCredentials
https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps-checkout
Checkout