Search code examples
kubernetesgitlabgitlab-cikubernetes-helmcontinuous-deployment

Gitlab-CI difference between multiline script and multiple scripts


Fairly new to GitLab-CI, I'm trying to deploy via Helm on a Kubernetes cluster. I have this:

image: docker:stable

deploy:
  stage: deploy
  image:
    name: alpine/helm:3.4.1
  script:
    - echo "Deploying to production"
    - helm list --all-namespaces

And it fails with:

Error: unknown command "sh" for "helm"

And the echo is not echoed, however, If I were to remove the echo line, the helm cmd would execute successfully.

I guess I'm asking how to make multiline scripts run? How do the gitlab-runner executes the series of commands provided in the script: array?


Solution

  • Each entry in the script array runs in an sh shell.

    sh -x 'echo "Deploying to production"'
    

    The alpine/helm image you are using contains an entrypoint of helm Which means the sh command gitlab is trying to run is being appended to the entrypoint as an argument (e.g. helm sh -x 'echo "Deploying to production"')

    Override the entrypoint

    deploy:
      stage: deploy
      image:
        name: alpine/helm:3.4.1
      entrypoint: [""]
      script:
        - echo "Deploying to production"