I've tried a bunch of different versions but the environment variable is never set.
These don't work. In all cases, the variable IMAGE
does not exist.
echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}" >> $GITHUB_ENV
echo ${IMAGE}
env:
DEPLOYMENT_NAME: my-deployment
echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}" >> $GITHUB_ENV
echo $IMAGE
env:
DEPLOYMENT_NAME: my-deployment
echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}" >> $GITHUB_ENV
echo ${{ env.IMAGE }}
env:
DEPLOYMENT_NAME: my-deployment
Edit
Some more experimentation. I tried setting the environment variables like this.
env:
IMAGE1: ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}
IMAGE2: "ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}"
This sets the variables - although I'd also like to be able to set them inside a job as described above. However, printing them in different ways always results in printing the variable names ${GITHUB_REPOSITORY}
and ${GITHUB_SHA}
rather than their content.
env:
DEPLOYMENT_NAME: my-deployment
IMAGE1: ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}
IMAGE2: ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}
...
echo $IMAGE1
echo $IMAGE2
echo ${IMAGE1}
echo ${IMAGE2}
echo "$IMAGE1"
echo "$IMAGE2"
echo "${IMAGE1}"
echo "${IMAGE2}"
ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}
ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}
ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}
ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}
ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}
ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}
ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}
ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA}
So although this is some progress I'm still wondering how the variables are set inside a job/run and how the content of the variables can be printed and not their name.
question from:
https://stackoverflow.com/questions/66045731/how-do-you-set-an-environment-variable-for-a-github-action 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…