2

This is similar to what is being asked here but with more explanation and desire for an up-to-date answer (answer uses set-env which is now deprecated)

Say I have the following github action yaml:

name: pull-request-pipeline
on: [pull_request]
jobs:
  deploy-to-dev-and-test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout action
        uses: actions/checkout@v2

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-west-2

      - name: Update API gateway definitions
        run: |
          aws apigateway put-rest-api --rest-api-id xxxxxxxx --mode merge --body 'file://SummitApi.yaml'

      - name: Get and store current deploymentId
        run: |
          OLD_DEPLOYMENT_ID=$(aws apigateway get-stage --rest-api-id xxxxxxxx --stage-name dev --query deploymentId --output text)
          echo '::set-output name=OLD_DEPLOYMENT_ID::$OLD_DEPLOYMENT_ID'
        id: old-deployment-id

      - name: Echo old deployment before deploy
        run: |
          echo ${{ steps.old-deployment-id.outputs.OLD_DEPLOYMENT_ID }}

      - name: Deploy to dev stage
        run: |
          aws apigateway create-deployment --rest-api xxxxxxxx --stage-name dev

      - name: Echo old deployment id after deploy
        run: |
          echo ${{ steps.old-deployment-id.outputs.OLD_DEPLOYMENT_ID }} 

When this runs it produces the following:

enter image description here

When taking another approach, specifically changing the Get and store current deploymentId step to:

      - name: Get and store current deploymentId
        run: |
          OLD_DEPLOYMENT_ID=$(aws apigateway get-stage --rest-api-id xxxxxxxx --stage-name dev --query deploymentId --output text)
          echo '::set-output name=OLD_DEPLOYMENT_ID::$OLD_DEPLOYMENT_ID'
        id: old-deployment-id

I get the following:

enter image description here

It seems like it sets the value of the output for the action to the unevaluated definitions of either $OLD_DEPLOYMENT or $(aws apigateway get-stage --rest-api-id xxxxxxxx --stage-name dev --query deploymentId --output text). I want to be able to store the value of the evaluated definition or in this case the actual deployment id from the cmd $(aws apigateway get-stage --rest-api-id xxxxxxxx --stage-name dev --query deploymentId --output text). Any ideas on how to do this with github actions?

References:

https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions

6
  • 3
    Use double quotes around the argument to echo instead of single quotes. Commented Jan 7, 2021 at 1:42
  • @BenjaminW. perfect thank you. What concept am I missing about single/double quotes? Is it a bash principle or github actions? Commented Jan 7, 2021 at 5:24
  • 1
    It's a Bash principle, see for example this Q&A. Commented Jan 7, 2021 at 13:39
  • @BenjaminW. thanks for your help. Commented Jan 7, 2021 at 19:49
  • @w33b did it solve your issue? If yes B3njamin, can you create a reply so it could be accepted as answer. Commented Jan 13, 2021 at 12:39

0

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.