【问题标题】:Any way to populate an Azure DevOps library variable from a shell script?有什么方法可以从 shell 脚本填充 Azure DevOps 库变量?
【发布时间】:2020-12-04 16:55:23
【问题描述】:

在执行 Azure DevOps 版本时,是否可以从 shell 脚本填充 Azure DevOps 库变量?

我的最终目标是在发布管道中的“替换令牌”任务中使用它,以便将秘密放入 yaml 中(比我目前拥有的要干净得多)。替换标记仅适用于 ADO 库变量。

我目前的解决方法是使用 sed 替换秘密给我的内容,并将其输出到另一个 yaml,我用它来部署 Kubernetes。任何替代方案都会很棒!

这是我现在拥有的 -

# Lets get the DB and Redis PW from AWS Secrets - used so we only have to set or change the passwords in one place - AWS Secrets
# Note that the AWS_secret_arn is different between stage and release and the variable is set in the library AppConfigs_xxxxx

DB_PW=$(aws secretsmanager get-secret-value --secret-id $(AWS_secret_arn) | jq -r '.SecretString' | jq -r '.db_pw')

echo " *** The secret is - " $DB_PW

# We are replacing the db_password with the one we acquired from AWS secrets
sed "s/db_pw_placeholder/$DB_PW/g" service.yaml > service-final.yaml

echo "### kubectl apply now running the service manifest ###"
kubectl apply -f service-final.yaml

我还想使用相同的方法从 AWS 获取其他参数以填充 ADO 变量库 - 例如 RDS DB 端点。

【问题讨论】:

  • 嗨@ErnieAndBert。这张票有什么更新吗?如果答案能给你一些帮助,请随时告诉我。只是提醒this

标签: amazon-web-services azure-devops azure-pipelines


【解决方案1】:

如果你使用这个Replace token,你真正需要的就是AWS Secrets Manager Get Secret task。它将来自 AWS Secret Manager 的秘密映射到秘密变量。既然Replace Token works with secrets,你应该没事。

【讨论】:

    【解决方案2】:

    我想分享另一种方法。

    除了可以使用 Azure DevOps 库变量来替换令牌任务之外,还可以使用构建过程中定义的管道变量。

    你可以对你的powershell代码做一些修改:

    例如:

    DB_PW=$(aws secretsmanager get-secret-value --secret-id $(AWS_secret_arn) | jq -r '.SecretString' | jq -r '.db_pw')
    
    echo " *** The secret is - " $DB_PW
    
    echo "##vso[task.setvariable variable=test]$DB_PW"
    

    那么变量$(test)就可以直接用在Replace tokens taks(#{test}#)中了。

    此方法使用logging command 定义管道中的变量

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-21
      • 1970-01-01
      • 2019-09-18
      • 2021-12-26
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多