I’m currently working on a GitLab CI/CD pipeline and I’m trying to use the sed command to dynamically update the contents of a file while the pipeline is running. My goal is to replace a placeholder version in a json file with a dynamic value that changes based on the pipeline execution context. I wrote a command in the .gitlab-ci.yml file, but I don’t know if my syntax is correct or if there is a better way.
My questions are:
Is the syntax of my sed command correct for use in a GitLab CI pipeline?
Is there a more efficient or recommended way to perform text replacement in files within a GitLab CI pipeline?
build:
image: node:alpine
services:
- docker:dind
variables:
VARIABLE: changed
before_script:
- [commands]
- [commands]
- [commands]
- |
sed -i 's/"version": "[^"]*"/"version": "'"$VARIABLE"'"/' app.json
script:
- cat app.json
This commands work on the runner :
$ sed -i 's/"version": "[^"]*"/"version": "'"$variable"'"/' app.json
$ cat app.json
{
"something": {
"version": "changed"
}
}
Hexca is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1