在天蓝色管道中使用来自 AWSCLI 的变量作为脚本

发布于 2025-01-20 22:11:34 字数 909 浏览 6 评论 0原文

我有一个构建过程,我需要使用通过AWSCLI接收的令牌。到目前为止,我已经将AWS连接到了我的Azure管道,但是我很难设置YAML。 我想获取相关令牌以稍后将其用作脚本中的变量。

如您在YAML中所见,我正在使用CodeArtifact运行一个PowerShell脚本,并且将值保存到我的 myOutputvar 中。 PowerShell脚本不会出错。 但是,稍后,当我运行构建脚本时,变量不存在,导致 echo关闭。

如何确保在脚本/构建部分中以后在任务中收到的值可以使用?

trigger:
- azure-pipelines

pool:
  vmImage: windows-latest

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'
- task: AWSPowerShellModuleScript@1
  inputs:
    awsCredentials: 'AWS Connection'
    regionName: 'eu-central-1'
    scriptType: 'inline'
    inlineScript: '##vso[task.setvariable variable=myOutputVar;]aws codeartifact get-authorization-token --domain somedomain  --domain-owner 444.... --query authorizationToken --output text; '
- script: |
    echo %myOutputVar%
    npm ci
    npm run build
  displayName: 'npm install and build'

I have a build process where I need to use a token, received through the AWSCLI. So far I have connected aws to my azure pipelines but I am having trouble setting up my yaml.
I want to fetch the relevant token to use it later as a variable in my script.

As you can see in my yaml I am running a powershell script with codeartifact and I am saving the value to my myOutputVar. The powershell script does not throw an error.
However, later when I run the building script that variable is not present resulting in ECHO is off.

How can I ensure the value received in the task can be used later in the script/build part?

trigger:
- azure-pipelines

pool:
  vmImage: windows-latest

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'
- task: AWSPowerShellModuleScript@1
  inputs:
    awsCredentials: 'AWS Connection'
    regionName: 'eu-central-1'
    scriptType: 'inline'
    inlineScript: '##vso[task.setvariable variable=myOutputVar;]aws codeartifact get-authorization-token --domain somedomain  --domain-owner 444.... --query authorizationToken --output text; '
- script: |
    echo %myOutputVar%
    npm ci
    npm run build
  displayName: 'npm install and build'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软糖 2025-01-27 22:11:34

您的内联脚本可以是多行,由于这是 PowerShell,您可以执行以下操作:

inlineScript: |
   $authToken = aws codeartifact get-authorization-token `
                    --domain somedomain `
                    --domain-owner 444.... `
                    --query authorizationToken `
                    --output text

   Write-Host "##vso[task.setvariable variable=myOutputVar;]$authToken"

Your inline script can be multiple lines, and since this is PowerShell you can do something like:

inlineScript: |
   $authToken = aws codeartifact get-authorization-token `
                    --domain somedomain `
                    --domain-owner 444.... `
                    --query authorizationToken `
                    --output text

   Write-Host "##vso[task.setvariable variable=myOutputVar;]$authToken"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文