I am using trying to build a workflow that will run in PowerShell. I am setting an environment for my branch name to use in a step for checkout of a different repository.
run: |
$branchName = $Env:GITHUB_REF -replace "refs/heads/", ""
echo "CURRENT_BRANCH=${branchName}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
In a later step, I'm trying to pass in the variable:
- name: Checkout repo
uses: actions/checkout@v2
with:
repository: 'MyOrg/MyRepo'
ref: ${env:CURRENT_BRANCH}
I've tried different formats involving curly brackets, but I keep getting output from the build that shows that exact text as the path. I'm not sure sure how to get it to evaluate.
When I do ${{ env:CURRENT_BRANCH }}
I received the following error:
The workflow is not valid. .github/workflows/publish.yml (Line: 54, Col: 14): Unexpected symbol: 'env:CURRENT_BRANCH'. Located at position 1 within expression: env:CURRENT_BRANCH
To set a custom environment variable, you must define it in the workflow file. The scope of a custom environment variable is limited to the element in which it is defined. You can define environment variables that are scoped for: The entire workflow, by using env at the top level of the workflow file.
We don't support to share variables between jobs. As you metioned artifacts, we would suggest you use it . You can write the version into a file , upload it as artifact in one job and then download the artifacts in the other job , read the file content.
Setting an environment variable echo "{name}={value}" >> $GITHUB_ENV. Creates or updates an environment variable for any actions running next in a job. The action that creates or updates the environment variable does not have access to the new value, but all subsequent actions in a job will have access.
To reference a variable from the given context (env
in this case) in the GitHub Actions workflow we have to use a dot (.
) character, but you used a colon (:
). To fix the error above the workflow should be adjusted:
- name: Checkout repo
uses: actions/checkout@v2
with:
repository: 'MyOrg/MyRepo'
ref: ${{env.CURRENT_BRANCH}}
Additionally, you don't have to detect the current branch on and pass it to the checkout action. actions/checkout@v2
will use the current branch by default. So you only have to have:
- name: Checkout repo
uses: actions/checkout@v2
- name: Next Step
[...]
One solution I found elsewhere and will post it here as an option, although I would like to know if using Environment Variables is possibly in my scenario. The solution is to use Outputs from a Step
- name: Output Variables
id: SetVariables
run: |
$branchName = $Env:GITHUB_REF -replace "refs/heads/", ""
echo "Branch: ${branchName}"
echo "::set-output name=branch::${branchName}"
- name: Checkout Repo 2
uses: actions/checkout@v2
with:
repository: 'MyOrg/MyRepo'
ref: ${{ steps.SetVariables.outputs.branch }}
This is a working method now, more info here:
echo "action_state=yellow" >> $GITHUB_ENV
The one below no longer works for me. A bit of research showed it is due to a security issue.
echo "::set-output name=action_state::yellow"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With