L
L
lilikon2019-11-19 14:52:14
GitLab
lilikon, 2019-11-19 14:52:14

How to change a line in a file in gitlab-ci?

Hello, I have the following issue. There is a .gitlab-ci.yml file in which you need to change a number of lines in the files before executing the docker build command, I will take the .env file as an example, you need to replace the DB_PASSWORD line.
Tried to execute:

docker-build:
  stage: build
  script:
    - perl -pi -e 's/DB_PASSWORD=(\w+){1,}/DB_PASSWORD=${TEST_DB_PASS}/g' .env.build
    - docker build -f docker/Dockerfile -t ${BASE_IMAGE}:latest .
  only:
    - develop
  tags:
    - docker

If you just run this command in the terminal it works fine, it also works in the image that runner uses. But when the runner itself executes it, it gives an error:
Can't open perl script "s/DB_PASSWORD=(\w+){1,}/DB_PASSWORD=${TEST_DB_PASS}/g": No such file or directory

I checked the contents of the folder, the .env.build file itself is in it. As I understand it, it swears at the script itself. Can you please tell me a command or a way to change the lines in the file?
I’ll add right away that you can’t overwrite this file with your hands in the project (the reason is the manual).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Karasik, 2019-11-19
@vitaly_il1

It seems to me that gitlab does not like something in the syntax. I would try wrapping it in a bash or perl script.
Script type
:
- inject_password.sh .env.build
- docker build -f docker/Dockerfile -t ${BASE_IMAGE}:latest .
Or you can not edit at all, but substitute the password through the environment variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question