我正在尝试捕获 Azure Pipeline $(System.AccessToken) 并在此管道中对其进行编码,以允许 NPM 安装对 Azure DevOps 中的我的源进行身份验证。
trigger:
- main
resources:
- repo: self
variables:
- group: Docker-Environment
- name: tag
value: '$(Build.BuildId)'
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool: Docker
workspace:
clean: all
steps:
- bash: |
NPM_PASS_SYS= printf "%s"":$(System.AccessToken)" | base64 # This looks Ok
env:
NPM_SYSTEM_TOKEN: "$NPM_PASS_SYS"
displayName: ECHO NPM_PASS_SYS VAR
- bash: |
echo $NPM_SYSTEM_TOKEN #EMPTY with $NPM_SYSTEM_TOKEN and $(NPM_SYSTEM_TOKEN)
displayName: "Echo the variable" …Run Code Online (Sandbox Code Playgroud) 我们拥有经典的管道设置和预部署批准,可以将生产发布推迟到决定发布的时间。像下面这样
这是 YAML 管道中的设置需求
最近公司采用了 azure devops yaml,所有管道现在都迁移到 Azure devops YAML。我被要求在 YAML 管道中设置类似的结构,人们可以在其中批准发布并将其推迟到特定时间。
如何在 YAML 管道中实现类似的设置?
在我的 NestJS 项目中,本地构建和运行是可行的,但是当在我的 Azure 管道中构建相同的代码时,它最近开始失败,因为在命令中找不到某些模块npm run build。当我在本地运行该命令时,没有任何问题并且可以正确构建。
有许多模块确实可以正确找到(或没有给出错误),那么为什么这些模块不能呢?您可以在 Imgur 上的此图像中找到我的文件布局的图像,并且相关文件可见。所有类都被声明为,export class ... {}并且大多数类也被导入到 AppModule 中,它们不会给出错误。
管道布置(相关部分):
trigger:
- master
- dev
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
displayName: 'Install Node 12'
inputs:
versionSpec: 12.0.0
- script: |
npm install -g typescript
npm install
npm test
displayName: 'run tests'
- script: |
npm run build
displayName: 'build dist folder'
Run Code Online (Sandbox Code Playgroud)
管道日志:(相关部分)
Generating script.
Script contents:
npm run build
========================== Starting Command Output ===========================
> fleetbot-nestjs@0.0.1 …Run Code Online (Sandbox Code Playgroud) 我试图从嵌套参数中获取值,如下所示:
parameters:
- name: myObject
type: object
default:
foo: FOO
things:
- one
nested:
one: apple
count: 3
Run Code Online (Sandbox Code Playgroud)
所以我期望写这样的东西${{ parameters.myObject.foo }}或${{ parameters.myObject.nested.one }}检索一个值。
还有一个循环遍历列表对象的示例,如下所示:
- name: listOfStrings
type: object
default:
- one
- two
steps:
- ${{ each value in parameters.listOfStrings }}:
- script: echo ${{ value }}
Run Code Online (Sandbox Code Playgroud)
这就是为什么我试图以这种方式获得价值,但它对我来说也不起作用:
- name: myObject
type: object
default:
foo: FOO
nested:
one: apple
steps:
- ${{ each value in parameters.myObject }}:
- script: echo ${{ value.foo }}
Run Code Online (Sandbox Code Playgroud)
不幸的是,微软没有在文档中提供示例https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops …
我正在尝试使用az pipelines管道中的 cli 更新变量组中的变量,我创建了一个 PAT 并将其传递到管道,其工作正常。但我使用默认的,例如$(System.AccessToken)它能够列出变量组中的变量,但无法更新变量组。其曰
错误:您无权对变量组执行此操作。变量组管理员应将您添加到管理员角色。##[错误]脚本失败,退出代码:1
经过一番搜索,我发现我需要将 Project Collection Build Service ( name ) 添加为变量组中的管理员,然后重试。我已经添加了这一点,但我仍然遇到同样的错误。有什么建议么?
我使用的是经典管道,这是从管道导出的任务。
steps
- task: AzureCLI@2
displayName: 'Azure CLI '
inputs:
azureSubscription: 'sc'
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
az extension add --name azure-devops
az pipelines variable-group variable list --group-id id --org "orgname" --project "projectname"
az pipelines variable-group variable update --group-id id --name apim-service-name --value $(str_tf_module_containername) --org "orgname" --project "projectname"
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
Run Code Online (Sandbox Code Playgroud) azure azure-cli azure-devops azure-pipelines azure-pipelines-yaml
我在我的 azure Devop 管道上遇到以下错误,它似乎与参数循环有关,但尽管以多种不同的方式编写脚本,我似乎无法摆脱它。YAML 验证器和我的 YAML linter 未检测到问题。
/azure-pipelines.yml (Line: 1, Col: 12): Unexpected value ''
下面是我的代码,它也使用了一个模板,我将把它包含在它下面。
azure-pipelines.yml
parameters:
steps:
- ${{ each project in parameters.projects }}:
- task: UsePythonVersion@0
displayName: 'Setting python version to 3.7'
inputs:
versionSpec: '3.7'
architecture: 'x64'
- script: |
pushd '$(System.DefaultWorkingDirectory)/${{ project }}'
pip install -r requirements.txt
displayName: 'Install prerequisites'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/${{ project }}'
includeRootFolder: false
archiveFile: '$(System.DefaultWorkingDirectory)/${{ project }}.zip'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)/${{ project }}.zip' …Run Code Online (Sandbox Code Playgroud) yaml azure pyyaml azure-pipelines-release-pipeline azure-pipelines-yaml
我有一个 YAML 脚本,如下所示:
jobs:
- job: UnixBuild
pool:
name: BuildMachinesUnix
steps:
- bash: echo "Build Unix"
- job: WinBuild
pool:
name: BuildMachinesWindows
steps:
- bash: echo "Build Windows"
- job: UnixRelease
dependsOn:
- UnixBuild
- WinBuild
condition: and(succeeded('UnixBuild'), succeeded('WinBuild'))
pool:
name: BuildMachinesUnix
steps:
- bash: echo "Release on Unix"
- job: WinRelease
dependsOn:
- UnixBuild
- WinBuild
condition: and(succeeded('UnixBuild'), succeeded('WinBuild'))
pool:
name: BuildMachinesWindows
steps:
- bash: echo "Release on Windows"
Run Code Online (Sandbox Code Playgroud)
每个池都有多个代理,我希望承担 UnixBuild 作业的代理也能处理 UnixRelease 作业,因为该版本的所有文件都在那里,这样我就不需要在发布步骤中重建它,并且WindowsBuild 也是如此
这样的事情可能吗?如果可能的话,怎么可能?
如果没有,对于如何仅在 Unix 和 …
在azuredevops yaml管道中,我们可以嵌套forloop吗?或多个for循环。
我的要求是通过映射的变量值迭代管道,这应该跨环境完成。
例如:在我的 ADO 存储库中,每个应用程序有 10 个文件夹,每个应用程序中每个环境有 4 个不同的变量模板文件,即“vars-development.yaml、vars-staging.yaml、vars-prod.yaml、vars-dr” .yaml”
我需要的是在每个环境特定变量模板中,我需要有不同的警报规则输入(每个环境会有多个警报)。变量.development.yaml
variables:
alert1:
environment: development
subscription: 'mysubscription'
resourceGroup: myrg
AlertRuleName: myalertrule
query:myquery
timeWindowInMinutes: 1
severity: 1
operator: GreaterThanOrEqual
threshold: 20
alert2:
environment: development
subscription: 'mysubscription'
resourceGroup: myrg
AlertRuleName: myalertrule
query:myquery
timeWindowInMinutes: 1
severity: 1
operator: GreaterThanOrEqual
threshold: 20
autoMitigate: false
etc.............
alertn:
Run Code Online (Sandbox Code Playgroud)
azure-pipeline.yaml
name: $(Build.SourceBranchName)-$(Build.BuildId)
trigger: none
parameters:
- name: appname
type: string
values:
- app1
- app2
- app3
- app4
- app5
- app5
stages:
- template: …Run Code Online (Sandbox Code Playgroud) azure-pipelines azure-pipelines-release-pipeline azure-pipelines-yaml
azure azure-devops azure-pipelines azure-aks azure-pipelines-yaml
我有一个包含几个 dotnet 项目的存储库,其中两个是 Web 项目,我需要指定要发布的项目。
我的 yaml 文件是:
trigger:
- master
pool:
vmImage: ubuntu-latest
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
projects: '**/Squil.Web.csproj'
arguments: '-o $(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: web'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
Run Code Online (Sandbox Code Playgroud)
只要我只有一个 Web 项目,类似的东西就可以工作,但在将大多数 Blazor 相关内容分解到另一个项目中后Squil.Razor,它就不再起作用了:发布任务总是选择那个项目,即 Razor 类库。
我也尝试使用'Squil.Web'作为projects参数,但无论我在那里放什么,它都会被忽略。
我已经为此烦恼了好几个小时了。我发现了一个相关的问题,从中我得到了语法'**/Squil.Web.csproj',但这对我来说也不起作用。
我知道我可以使用 dotnet 命令行,但我宁愿使用该任务。
这是.NET 6。
还有什么可以尝试的?
我有以下模板可以进行多阶段部署:
parameters:
- name: Stage
type: string
- name: Environment
type: string
- name: Enabled
type: boolean
default: false
- name: WebAppName
type: string
- name: ArtifactName
type: string
stages:
- stage: ${{ parameters.Stage }}
displayName: '${{ parameters.Stage }} Stage'
dependsOn: '${{ parameters.DependsOn }}'
jobs:
- deployment: ${{ parameters.Environment }}
timeoutInMinutes: 70
environment: '${{ parameters.Environment }} Environment'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: DownloadBuildArtifacts@0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: ${{ parameters.ArtifactName }}
downloadPath: '$(System.ArtifactsDirectory)'
- task: …Run Code Online (Sandbox Code Playgroud) azure-devops ×6
azure ×3
azure-pipelines-release-pipeline ×2
yaml ×2
.net ×1
azure-aks ×1
azure-cli ×1
nestjs ×1
node.js ×1
pyyaml ×1