0

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'

1 Answer 1

1

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"
Sign up to request clarification or add additional context in comments.

1 Comment

Thx for the solid explanation. This is how it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.