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:
notification job:
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:
next step:
2
Answers
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:
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.
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.
deploy job output:
notification job output: