在天蓝色管道中使用来自 AWSCLI 的变量作为脚本
我有一个构建过程,我需要使用通过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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的内联脚本可以是多行,由于这是 PowerShell,您可以执行以下操作:
Your inline script can be multiple lines, and since this is PowerShell you can do something like: