I configured a workaround solution. My approach involved utilizing envsubst, a template file, and a trigger with the use of artifacts.
```yaml
# .gitlab-ci.yml
stages:
- trigger
variables:
PROJECTS: '["project1", "project2", "project3"]'
process:template:
stage: trigger
before_script:
- apt-get update
- apt-get install gettext-base
script:
- envsubst '${PROJECTS}' < template.yml > template.gitlab-ci.yml
artifacts:
paths:
- template.gitlab-ci.yml
trigger:template:
stage: trigger
trigger:
include:
- artifact: template.gitlab-ci.yml
job: process:template
forward:
pipeline_variables: true
needs:
- job: process:template
```
Should have the `template.yml` file present within your repository:
```yaml
# template.yml
stages:
- matrix
deploy:
stage: matrix
parallel:
matrix:
- PROJECT: ${PROJECTS}
script:
- echo "Deploying project = ${PROJECT}"
```
The final pipeline looks like this:
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/joLuf.png
And in the output of each job from matrix we can see message from the echo:
- `deploy: [project1]` "Deploying project = project1"
- `deploy: [project2]` "Deploying project = project2"
- `deploy: [project3]` "Deploying project = project3"
*Hope this helps!* 🥷
To address the need for passing variables to the parallel:matrix effectively, I configured a workaround solution. My approach involved utilizing envsubst, a template file, and a trigger with the use of artifacts.
```yaml
# .gitlab-ci.yml
stages:
- trigger
variables:
PROJECTS: '["project1", "project2", "project3"]'
process:template:
stage: trigger
before_script:
- apt-get update
- apt-get install gettext-base
script:
- envsubst '${PROJECTS}' < template.yml > template.gitlab-ci.yml
artifacts:
paths:
- template.gitlab-ci.yml
trigger:template:
stage: trigger
trigger:
include:
- artifact: template.gitlab-ci.yml
job: process:template
forward:
pipeline_variables: true
needs:
- job: process:template
```
Should have the `template.yml` file present within your repository:
```yaml
# template.yml
stages:
- matrix
deploy:
stage: matrix
parallel:
matrix:
- PROJECT: ${PROJECTS}
script:
- echo "Deploying project = ${PROJECT}"
```
The final pipeline looks like this:
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/joLuf.png
And in the output of each job from matrix we can see message from the echo:
- `deploy: [project1]` "Deploying project = project1"
- `deploy: [project2]` "Deploying project = project2"
- `deploy: [project3]` "Deploying project = project3"
*Hope this helps!* 🥷