Running pipelines in parallel
My problem is something like this. I have a web application served on two servers. I’m deploying the source code via git and sometimes I need further commands like “npm run prod”. Currently my GitLab does the following (among others)
It first pulls down the code to Master 1, then to Master 2 (not in parallel), then executes npm-run-prod-1 and after that npm-run-prod-2. What I wish to do is to pull the code to both servers in parallel and not in one job. Same to npm-run-prod jobs, tho they have to depend on the previous corresponting job. Like npm-run-prod-1 can only start if git-pull-master-1 succeeded. Here is this part of my CI/CD file:
stages:
- git-pull-master
- npm-run-prod-master
git-pull-master-1:
image: panubo/sshd
environment:
name: master
url: https://MYPROJECT_URL
stage: git-pull-master
only:
- master
before_script:
- apk add --update openssh-client bash
- eval $(ssh-agent -s)
- bash -c 'ssh-add <(echo "$MASTER_PRIVATE_KEY")'
- echo $MASTER_HOST_KEY1 > ~/.ssh/known_hosts
script: ssh $MASTER_IP1 -A "cd $MASTER_FOLDER && git pull origin master && exit"
git-pull-master-2:
image: panubo/sshd
environment:
name: master
url: https://MYPROJECT_URL
stage: git-pull-master
only:
- master
before_script:
- apk add --update openssh-client bash
- eval $(ssh-agent -s)
- bash -c 'ssh-add <(echo "$MASTER_PRIVATE_KEY")'
- echo $MASTER_HOST_KEY2 >> ~/.ssh/known_hosts
script: ssh $MASTER_IP2 -A "cd $MASTER_FOLDER && git pull origin master && exit"
npm-run-prod-master-1:
image: panubo/sshd
environment:
name: master
url: https://MYPROJECT_URL
stage: npm-run-prod-master
only:
refs:
- master
changes:
- resources/assets/**/*
- "webpack.mix"
before_script:
- apk add --update openssh-client bash
- eval $(ssh-agent -s)
- bash -c 'ssh-add <(echo "$MASTER_PRIVATE_KEY")'
- echo $MASTER_HOST_KEY1 > ~/.ssh/known_hosts
script: ssh $MASTER_IP1 -A "cd $MASTER_FOLDER && npm run prod && exit"
npm-run-prod-master-2:
image: panubo/sshd
environment:
name: master
url: https://MYPROJECT_URL
stage: npm-run-prod-master
only:
refs:
- master
changes:
- resources/assets/**/*
- "webpack.mix"
before_script:
- apk add --update openssh-client bash
- eval $(ssh-agent -s)
- bash -c 'ssh-add <(echo "$MASTER_PRIVATE_KEY")'
- echo $MASTER_HOST_KEY2 >> ~/.ssh/known_hosts
script: ssh $MASTER_IP2 -A "cd $MASTER_FOLDER && npm run prod && exit"
I don’t know if I explained my problem and what I want to achieve here. I just want to pull the code to the servers at the same time and run “npm run prod” also at the same time, but only if the pull succeeded on the specific server (so run-prod-1 if git pull on 1st server succeeded, and run-prod-2 if git pull succeeded on the 2nd server)