2020-07-19 10:31:54 +00:00
|
|
|
stages:
|
2021-06-20 00:25:27 +00:00
|
|
|
- test
|
2020-07-19 10:31:54 +00:00
|
|
|
- failed_stage
|
|
|
|
|
|
|
|
image: node:lts-alpine # Use latest LTS version of Node.js on Alpine
|
|
|
|
|
|
|
|
deploy_job:
|
2021-06-20 00:25:27 +00:00
|
|
|
stage: test
|
2020-07-19 10:31:54 +00:00
|
|
|
|
|
|
|
before_script:
|
2021-05-22 03:08:26 +00:00
|
|
|
- 'which ssh-agent || (apk update && apk add git openssh-client)'
|
2020-07-19 10:31:54 +00:00
|
|
|
- eval $(ssh-agent -s)
|
|
|
|
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
|
|
|
|
- mkdir -p ~/.ssh
|
|
|
|
- chmod 700 ~/.ssh
|
|
|
|
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
|
|
|
|
- chmod 644 ~/.ssh/known_hosts
|
|
|
|
|
|
|
|
script:
|
2021-05-22 03:06:13 +00:00
|
|
|
- sh src/script.sh
|
2020-07-19 10:31:54 +00:00
|
|
|
|
|
|
|
- git checkout master
|
|
|
|
- git config --global user.name "curben-bot"
|
|
|
|
- git config --global user.email "3048979-curben-bot@users.noreply.gitlab.com"
|
|
|
|
|
|
|
|
# Commit the changes
|
2021-05-22 03:09:42 +00:00
|
|
|
- sh src/commit.sh
|
2020-07-19 10:31:54 +00:00
|
|
|
|
|
|
|
# Generate successful status badge
|
|
|
|
- mkdir -p .gitlab/
|
2021-05-22 03:09:42 +00:00
|
|
|
- sh src/badge.sh "success"
|
2020-07-19 10:31:54 +00:00
|
|
|
- git add .gitlab/status.svg
|
|
|
|
# Only commit when diff exists https://stackoverflow.com/a/8123841
|
|
|
|
- git diff-index --quiet HEAD || git commit -m "Success pipeline"
|
|
|
|
|
|
|
|
- ssh -T git@gitlab.com
|
2021-05-29 05:12:22 +00:00
|
|
|
- git remote set-url origin git@gitlab.com:curben/tracking-filter.git
|
2020-07-19 10:31:54 +00:00
|
|
|
- git push origin master
|
|
|
|
|
|
|
|
rules:
|
|
|
|
# Only trigger through schedule job in master branch
|
|
|
|
- if: '$CI_COMMIT_REF_NAME == "master" && $CI_PIPELINE_SOURCE == "schedule"'
|
|
|
|
when: always
|
|
|
|
# Only trigger through "Run pipeline" in master branch
|
|
|
|
- if: '$CI_COMMIT_REF_NAME == "master" && $CI_PIPELINE_SOURCE == "web"'
|
|
|
|
when: always
|
|
|
|
|
2021-05-29 05:15:50 +00:00
|
|
|
# Upload working folder as a job artifact
|
|
|
|
artifacts:
|
|
|
|
paths:
|
|
|
|
- tmp/
|
|
|
|
expire_in: 30 days
|
|
|
|
|
2020-07-19 10:31:54 +00:00
|
|
|
failed_job:
|
|
|
|
stage: failed_stage
|
|
|
|
|
|
|
|
before_script:
|
|
|
|
- 'which ssh-agent || (apk update && apk add openssh-client git)'
|
|
|
|
- eval $(ssh-agent -s)
|
|
|
|
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
|
|
|
|
- mkdir -p ~/.ssh
|
|
|
|
- chmod 700 ~/.ssh
|
|
|
|
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
|
|
|
|
- chmod 644 ~/.ssh/known_hosts
|
|
|
|
|
|
|
|
script:
|
|
|
|
- git checkout master
|
|
|
|
- git config --global user.name "curben-bot"
|
|
|
|
- git config --global user.email "3048979-curben-bot@users.noreply.gitlab.com"
|
|
|
|
|
|
|
|
- mkdir -p .gitlab/
|
2021-05-22 03:09:42 +00:00
|
|
|
- sh src/badge.sh "failed"
|
2020-07-19 10:31:54 +00:00
|
|
|
- git add .gitlab/status.svg
|
|
|
|
- git diff-index --quiet HEAD || git commit -m "Failed pipeline"
|
|
|
|
- ssh -T git@gitlab.com
|
2021-05-29 05:12:22 +00:00
|
|
|
- git remote set-url origin git@gitlab.com:curben/tracking-filter.git
|
2020-07-19 10:31:54 +00:00
|
|
|
- git push origin master
|
|
|
|
|
|
|
|
rules:
|
|
|
|
- if: '$CI_COMMIT_REF_NAME == "master" && $CI_PIPELINE_SOURCE == "schedule"'
|
|
|
|
# Run this job only when deploy_job failed
|
|
|
|
when: on_failure
|
|
|
|
- if: '$CI_COMMIT_REF_NAME == "master" && $CI_PIPELINE_SOURCE == "web"'
|
|
|
|
when: on_failure
|
2021-06-20 00:25:27 +00:00
|
|
|
|
|
|
|
include:
|
|
|
|
- template: Security/Secret-Detection.gitlab-ci.yml
|