我实际上想做的是:针对不同环境使用具有相同部署脚本的管道。每个环境都有一个变量组,其中包含部署所需的设置。
但在 YAML 文件中指定非硬编码的变量组似乎很困难。我希望管道有一个管道变量来指定要使用的变量组。
我发现了一些使用模板似乎可以实现这一点的指示。如果这是唯一的方法,那就这样吧。但我希望有一种更直接的方法。
我使用 Azure Pipelines 来构建我的解决方案。手动构建时,用户可以决定使用哪个构建配置。现在我希望默认值(以及自动触发时的值)根据分支而不同。这是我的(非工作)方法:
name: PR-$(Build.SourceBranchName)-$(Date:yyyyMMdd)$(Rev:.r)
trigger:
- develop
- test
- master
pool:
vmImage: 'windows-latest'
parameters:
- name: BuildConfiguration
displayName: Build Configuration
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/develop') }}:
default: Debug
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/test') }}:
default: Release
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}:
default: Release
values:
- Debug
- Release
Run Code Online (Sandbox Code Playgroud)
条件部分 ( ${{...}) 根本不起作用。(* "A template expression is not allowed in this context")
还有其他方法可以实现这一点吗?
我想使用 Azure DevOps API 为我的用户创建 PAT。但我还无法进行身份验证。在Microsoft 的这份文档中,他们声明可以使用 PAT 进行身份验证,但事实并非如此。我收到带有登录页面的 HTTP 203 响应。
PS:我正在使用 Postman 来测试 API 请求。
我想包含一个取决于变量 Agent.OS 的模板:
...
steps:
- ${{ if eq(variables['Agent.OS'], 'Linux') }}:
- template: /templates/prepare-tool.yaml
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。我在步骤列表中没有看到此步骤。我也尝试过:
- ${{ if eq(variables.AGENT_OS, 'Linux') }}:
Run Code Online (Sandbox Code Playgroud)
结果一样。
也许我错了,但是:
运行时和编译时表达式语法之间的区别主要在于可用的上下文。在编译时表达式 (${{ }}) 中,您可以访问参数和静态定义的变量。在运行时表达式 ($[ ]) 中,您可以访问更多变量,但不能访问参数。
所以,我必须使用- $[ if eq(...这个变量,它不是静态的,但它也不起作用:
意外值 '$[ if eq(variables.
我不知道如何使用这种变量。
我将代码存储在 Azure Dev Ops git 存储库的各个分支中。
开发人员是否可以以某种方式推送到分支,传递某种命令行标志,这将停止为该分支执行的任何管道?
我有许多管道设置为在检测到我的分支发生更改时运行。
工作流程:
features/abc)我的pipeline.yml文件设置如下:
trigger:
batch: true
branches:
include:
- features/*
Run Code Online (Sandbox Code Playgroud)
当开发者推送到feature/abc管道就会启动。
我想知道当我输入时是否可以在命令行上设置某种标志git push来阻止管道执行。
我有一个使用模板化作业的管道,如下所示:
- template: '/pipeline/templates/jobs/DeployInfraToRegion.yml@devops'
parameters:
...
Run Code Online (Sandbox Code Playgroud)
此作业将编译的 Bicep 模板部署到 Azure。该模板创建一个 KeyVault 并输出其名称,如下所示:
output sqlSecretsKeyVaultName string = keyvault.outputs.keyVaultName
Run Code Online (Sandbox Code Playgroud)
上面的模板包含一个名为DeployInfrastruct的作业:
jobs:
- deployment: DeployInfrastructure
displayName: Deploy Infrastructure
variables:
...
Run Code Online (Sandbox Code Playgroud)
它运行一个最终任务,该任务获取所有输出并将它们设置为管道变量:
- task: PowerShell@2
name: SetArmOutputsForRegion
displayName: "Set Arm outputs as variables"
inputs:
targetType: inline
pwsh: true
errorActionPreference: stop
script: |
$armOutputString = '$(${{ parameters.armOutputVariable }})'
$armOutputObj = $armOutputString | convertfrom-json
$armOutputObj.PSObject.Properties | ForEach-Object {
$type = ($_.value.type).ToLower()
$key = $_.name
$value = $_.value.value
if ($type -eq "securestring") {
Write-Host "##vso[task.setvariable …Run Code Online (Sandbox Code Playgroud) 我正在使用 Azure Devops 管道,其中有一项任务将创建 KVM 来宾 VM,一旦通过主机内的打包程序创建 VM,它将运行 bash 脚本来检查来宾 VM 内运行的服务的状态。如果任何服务未运行或抛出错误,则此 bash 脚本将以代码 3 退出,因为我已在 bash 脚本中添加了值,如下所示
设置-e
因此,如果上述 bash 脚本失败,我希望任务失败,但问题与创建 KVM 来宾虚拟机的任务相同,因此在启动和关闭时它会抛出预期的错误,但我不希望此任务由于这些错误而失败,但是只有 bash 脚本才会失败。
我在任务“标准错误失败”中选择了选项,但不确定我们如何专门针对 bash 脚本错误使任务失败,任何人都可以对此有一些建议吗?
是否可以在 Azure DevOps 管道中并行运行前两个阶段?默认情况下,每个阶段仅在前一个阶段完成后启动,除非通过 dependentOn 属性另有指定。
目前的情况是:
我想并行运行 iOS_Dev_Build 和 iOS_QA_Build 这两个阶段。没有为 iOS_QA_Build 添加 dependentOn 条件。但默认情况下,它会等待 iOS_Dev_Build 阶段完成才开始
pipeline devops azure-devops azure-pipelines azure-pipelines-release-pipeline
我的 Azure 管道 SSH 配置工作正常,直到我将 ubuntu 从 Ubuntu20 升级到 Ubuntu 22。现在我收到以下消息:
##[error]Failed to connect to the remote machine. Verify the SSH service connection details. Error: Error: All configured authentication methods failed.
我该如何调试这个?我可以使用我的 ssh 密钥 ssh 到我的服务器,没有任何问题。
有没有办法让我更多地了解该问题并进行调试?
此外,Azure pipeline 上有这样的公告:
Azure DevOps 继续推出更改,以永久禁用通过 TLS 1.0、TLS 1.1 和 TLS 1.2 弱密码套件进行的通信。如果您的工具依赖于旧版 TLS 来与 Azure DevOps 进行通信,请采取必要的操作来启用 TLS 1.2,如博客中所述。
这可能有关系吗?非常感谢所有帮助。
这是我的要求.txt
beautifulsoup4==4.11.1
cachetools==5.2.0
certifi==2022.12.7
charset-normalizer==2.1.1
click==8.1.3
colorama==0.4.6
Flask==2.2.2
Flask-SQLAlchemy==3.0.2
google==3.0.0
google-api-core==2.10.2
google-auth==2.14.1
google-cloud-pubsub==2.13.11
googleapis-common-protos==1.57.0
greenlet==2.0.1
grpc-google-iam-v1==0.12.4
grpcio==1.51.1
grpcio-status==1.51.1
idna==3.4
importlib-metadata==5.2.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.1
NotFound==1.0.2
proto-plus==1.22.1
protobuf==4.21.12
psycopg2==2.9.5
pyasn1==0.4.8
pyasn1-modules==0.2.8
requests==2.28.1
rsa==4.9
six==1.16.0
soupsieve==2.3.2.post1
SQLAlchemy==1.4.45
urllib3==1.26.13
Werkzeug==2.2.2
zipp==3.11.0
Run Code Online (Sandbox Code Playgroud)
这是我的 Dockerfile
FROM python:3.10-slim
# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True
# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
# Install production dependencies.
RUN pip install …Run Code Online (Sandbox Code Playgroud) azure-pipelines ×10
azure-devops ×6
azure ×3
pipeline ×2
azure-pipelines-release-pipeline ×1
bash ×1
devops ×1
docker ×1
dockerfile ×1
python ×1
ssh ×1
tfs ×1
yaml ×1