Spinnaker: When running GCB with definition (cloudbuild.yaml) from artifacts, SpEL is not evaluated

Created on 22 Oct 2019  路  1Comment  路  Source: spinnaker/spinnaker

Issue Summary:

When running GDB (google cloud build) with definition file (cloudbuild.yaml pushing from git f.ex) from artifacts, SpEL is not evaluated. However, when GCB definition is defined as text directly in spinnaker, SpEL is evaluated.

I think spinnaker should download the cloudbuild.yaml from artifacts then evaluate SpEL before sending to GCB.

Cloud Provider(s):

Kubernetes V2

Environment:

Running GCB from spinnaker

Feature Area:

Pipelines

Description:

Define GCB substitutions with value is SpEL, for example:
If the GCB build configuration is defined as text directly in spinnaker -> SpEL is evaluated.
If the GCB build configuration is passed as file from artifacts -> SpEL is not evaluated.

Steps to Reproduce:

  1. GCB definition with substitution to get the current stage name:
steps:
  - args:
      - '-c'
      - |
        set -e
        if [[ "${_SPINNAKER_CURRENT_STAGE_NAME}" == *"terraform plan"* ]]; then
            echo Running terraform plan
        fi
        if [[ "${_SPINNAKER_CURRENT_STAGE_NAME}" == *"terraform apply"* ]]; then
            echo Running terraform apply
        fi
    entrypoint: bash
    name: 'gcr.io/${PROJECT_ID}/terraform'
substitutions:
  _SPINNAKER_CURRENT_STAGE_NAME: '${ #currentStage()["name"].toString() }'
  1. Create terraform plan stage to run GCB
  2. Put above GCB build definition as text directly in spinnaker pipeline configuration.
  3. The SpEL: '${ #currentStage()["name"].toString() }' will be evaluated making the above definition when running become:
steps:
  - args:
      - '-c'
      - |
        set -e
        if [[ "terraform plan" == *"terraform plan"* ]]; then
            echo Running terraform plan
        fi
        if [[ "terraform plan" == *"terraform apply"* ]]; then
            echo Running terraform apply
        fi
  1. So with GCB build definition defined as text, the GCB work as expected.
  2. Now store above GCB definition as file in git repo and push to spinnaker as artifact, then configure GCB stage to use the artifact file instead.
  3. With GCB definition passed as artifact, the above GCB will become:
steps:
  - args:
      - '-c'
      - |
        set -e
        if [[ "${ #currentStage()["name"].toString() }" == *"terraform plan"* ]]; then
            echo Running terraform plan
        fi
        if [[ "${ #currentStage()["name"].toString() }" == *"terraform apply"* ]]; then
            echo Running terraform apply
        fi

Additional Details:

gcb_text
gcb_artifact
gcb_artifact_1


_Please delete the instructions below this line prior to submitting_

bug componenorca

Most helpful comment

Hey @mdk194, thanks for opening this detailed issue! I've submitted a fix which will go out with the next version of Spinnaker (1.17).

>All comments

Hey @mdk194, thanks for opening this detailed issue! I've submitted a fix which will go out with the next version of Spinnaker (1.17).

Was this page helpful?
0 / 5 - 0 ratings