skip to Main Content

I have the following GitHub Actions, I want to pass lastNotificationMessage from deploy job to the next job (for the details please check the screenshots):

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Get last notification
        if: always()
        id: notification
        timeout-minutes: 1
        run: |
          LAST_NOTIFICATION=$(app get-last-notification)
          echo "$LAST_NOTIFICATION"
          echo "CUSTOM_LAST_NOTIFICATION=$LAST_NOTIFICATION" >> $GITHUB_ENV

    outputs:
      lastNotificationMessage: ${{ env.CUSTOM_LAST_NOTIFICATION }}
      # otherVariable: other value
      # otherVariable: other value
      # otherVariable: other value
      # otherVariable: other value
      # otherVariable: other value
      # otherVariable: other value


  notification:
    runs-on: ubuntu-latest
    needs: deploy
    if: always()

    steps:
      - name: Notification
        timeout-minutes: 1
        run: |
          app send-notification 
            --last-message "$LAST_NOTIFICATION_MESSAGE"
        env:
          LAST_NOTIFICATION_MESSAGE: ${{ needs.deploy.outputs.lastNotificationMessage }}

When I echo it on the first job, it already has value (it’s in base64url-encoded format to make sure it doesn’t have any dangerous character).

But on the next job, When I check it in the job output, it’s alway empty. I can see that the other variables have correct value also.

What is the issue here and how can I fix it?

Below is the screenshot:

deploy job:

enter image description here

notification job:

enter image description here

Other method suggested by @Shayki which I tried but not success:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Deploy
        id: deployToCloud
        timeout-minutes: 1
        run: |
          echo "deploymentId=$DEPLOYMENT_ID" >> $GITHUB_OUTPUT

      - name: Get last notification
        if: always()
        id: lastNotification
        timeout-minutes: 1
        run: |
          LAST_NOTIFICATION=$(app get-last-notification)
          echo "$LAST_NOTIFICATION"
          echo "lastNotificationMessage=$LAST_NOTIFICATION" >> $GITHUB_OUTPUT

    outputs:
      deploymentId: ${{ steps.deployToCloud.outputs.deploymentId }}
      lastNotificationMessage: ${{ steps.lastNotification.outputs.lastNotificationMessage }}

  notification:
    runs-on: ubuntu-latest
    needs: deploy
    if: always()

    steps:
      - name: Notification
        timeout-minutes: 1
        run: |
          app send-notification 
            --last-message "$LAST_NOTIFICATION_MESSAGE"
        env:
          DEPLOYMENT_ID: ${{ needs.deploy.outputs.deploymentId }}
          LAST_NOTIFICATION_MESSAGE: ${{ needs.deploy.outputs.lastNotificationMessage }}

deploy step:

enter image description here

next step:

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    I found the reason:

    The value stored in the variable contains the base64url encoded of one secret key. I thought github will not smart enough to detect it, but it does.

    GitHub doesn't allow passing variable that contains secret value from one job to other jobs. It already tell in in the summary but I miss it:

    Skip output 'lastNotificationMessage' since it may contain secret.
    

    Since I cannot pass the variable to the next jobs, I print it to the console for checking only, my final code will not contains those echoes.


  2. There logic in your workflow looks correct. I tried running it with some simplification and was able to see the value in both jobs printed in GitHub logs.

    name: output
    
    on:
      workflow_dispatch
    
    jobs:
      deploy:
        runs-on: ubuntu-latest
        steps:
          - name: Get last notification
            if: always()
            id: notification
            timeout-minutes: 1
            run: |
              LAST_NOTIFICATION=1234567890
              echo "$LAST_NOTIFICATION"
              echo "CUSTOM_LAST_NOTIFICATION=$LAST_NOTIFICATION" >> $GITHUB_ENV
        outputs:
          lastNotificationMessage: ${{ env.CUSTOM_LAST_NOTIFICATION }}
    
      notification:
        runs-on: ubuntu-latest
        needs: deploy
        if: always()
        steps:
          - name: Notification
            timeout-minutes: 1
            run: |
              echo "$LAST_NOTIFICATION_MESSAGE"
            env:
              LAST_NOTIFICATION_MESSAGE: ${{ needs.deploy.outputs.lastNotificationMessage }}
    

    deploy job output:

    Run LAST_NOTIFICATION=1234567890
      LAST_NOTIFICATION=1234567890
      echo "$LAST_NOTIFICATION"
      echo "CUSTOM_LAST_NOTIFICATION=$LAST_NOTIFICATION" >> $GITHUB_ENV
      shell: /usr/bin/bash -e {0}
    1234567890
    

    notification job output:

    Run echo "$LAST_NOTIFICATION_MESSAGE"
      echo "$LAST_NOTIFICATION_MESSAGE"
      shell: /usr/bin/bash -e {0}
      env:
        LAST_NOTIFICATION_MESSAGE: 1234567890
    1234567890
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search