I am new to devops and I am having the following problem:
I have cloudbuild file which configured to generate deployment for namespace named after tag.
For example: for tag v1.0.2/host/dev it should generate new deployment at "dev" namespace.
Here is part of cloudbuild.yaml code:
  - name: 'gcr.io/cloud-builders/gcloud'
    entrypoint: 'bash'
    args:
    - '-c'
    - |
        export APP_VERSION
        export NAMESPACE
        export CLUSTER_NAME
        IFS=/ read -r APP_VERSION CLUSTER_NAME NAMESPACE <<< "$TAG_NAME"
        ... here is my problem ...
        export ENVIRONMENT
        export X
        export XX
        IFS=/ read -r X XX ENVIRONMENT <<< "$TAG_NAME"
        ...As you can see - variable NAMESPACE is set with last part of tag (like "dev")
Later in code i need to set one more variable - ENVIRONMENT - with same value ("dev"). I did it by copy the way it done before and use some X and XX unused variables.
How can this be done in more accurate way? I tried:
export ENVIRONMENT=NAMESPACEOr:
export ENVIRONMENT=${NAMESPACE}Any ideas?
This should do it:
export ENVIRONMENT=${NAMESPACE}Basically, you are doing an
export NAMESPACEbefore the said assignment and in bash NAMESPACE should be available as a variable ${NAMESPACE}