Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab CI/CD - Change Working Directory

I am trying to implement a CI/CD pipeline for Terraform, however I need to change the pwd before running any further commands.

It appears the Terraform container only accepts Terraform commands, so cd/ls/echo $PATH are unrecognised. Do I need build an image which supports this and use that, or can I use the maintained Terraform images?

I tried changing the ENTRYPOINT but appears only a minimal install is available due to the Alpine image.

like image 608
Sphinx's Avatar asked Apr 23 '18 18:04

Sphinx's


People also ask

Where is the GitLab runner build directory?

Build Directory GitLab Runner clones the repository to a path that exists under a base path better known as the Builds Directory. The default location of this base directory depends on the executor. For: Kubernetes, Docker and Docker Machine executors, it is /builds inside of the container.

Where is GitLab CI Yml located?

From version 7.12, GitLab CI uses a YAML file ( . gitlab-ci. yml ) for the project configuration. It is placed in the root of your repository and contains definitions of how your project should be built.

How CI CD pipeline works in GitLab?

GitLab CI/CD fits in a common development workflow. You can start by discussing a code implementation in an issue and working locally on your proposed changes. Then you can push your commits to a feature branch in a remote repository that's hosted in GitLab. The push triggers the CI/CD pipeline for your project.


2 Answers

You can change the entrypoint to /usr/bin/env in order to run a cd command. Example with gitlab-ci:

validate_terraform:
  image:
    name: hashicorp/terraform:light
    entrypoint: ["/usr/bin/env"]
  stage: test

  script:
    - cd infrastructure/
    - terraform init
    - terraform validate
like image 124
Jerome Leclanche Avatar answered Oct 21 '22 14:10

Jerome Leclanche


You could just use a generic image like alpine in your .gitlab-ci.yml and get the Terraform inside your script like:

wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_386.zip
unzip terraform*

and use it like:

./terraform [...]
like image 34
alirabiee Avatar answered Oct 21 '22 13:10

alirabiee