[github actions] shell parameter expansion: replace character ( ${parameter/%pattern/string}
)
#45488
-
Select Topic AreaQuestion BodyI am trying to use In google cloud simple But I can't make it work in github actions. How to https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 6 replies
-
@kwladyka You can use the sed command to replace a pattern with a string in shell parameter expansion. TAG_NAME="0.0.1" TAG_NAME="0.0.1" |
Beta Was this translation helpful? Give feedback.
-
Thank you @jge162 . Still would like to find a way to set it up on the beginning of the file in |
Beta Was this translation helpful? Give feedback.
-
There is only very limited support for string formatting in the Actions syntax itself, see Expressions. For anything more complex you'll need to use steps and create outputs (or environment variables) to set the values you want (e.g. using shell syntax). |
Beta Was this translation helpful? Give feedback.
-
Is a way to do something like below? BUT with
|
Beta Was this translation helpful? Give feedback.
-
There's no way to dynamically set an environment variable for all jobs. But you could use outputs to transfer the values between jobs (mind that this requires a jobs:
set-vars:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.gen_version.outputs.VERSION }}
steps:
- name: set values
id: gen_version
run: |
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Use the value
# this sets environment variables for this step
env:
VERSION: ${{ steps.gen_version.outputs.VERSION }}
run: |
echo "${VERSION}"
other-job:
needs: [set-vars]
runs-on: ubuntu-latest
# this sets environment variables for the whole job
env:
VERSION: "${{ needs.set-vars.outputs.version }}"
steps:
- name: Use the value
run: |
echo "${VERSION}" A Note that I've changed the |
Beta Was this translation helpful? Give feedback.
-
Why? I was trying with |
Beta Was this translation helpful? Give feedback.
-
This is invalid shell syntax, because of the spaces between the curly braces and the variable name:
The following should work:
Mind that |
Beta Was this translation helpful? Give feedback.
-
Thank you. I wish to have a way to set it as global environment like |
Beta Was this translation helpful? Give feedback.
-
Job-level |
Beta Was this translation helpful? Give feedback.
There's no way to dynamically set an environment variable for all jobs. But you could use outputs to transfer the values between jobs (mind that this requires a
needs
relationship between the jobs):