2020-07-05 10:46:19 +00:00
|
|
|
stages:
|
2020-12-12 21:54:08 +00:00
|
|
|
- build
|
|
|
|
- deploy
|
2020-07-05 10:46:19 +00:00
|
|
|
- failed_stage
|
|
|
|
|
|
|
|
image: alpine:latest # Use the latest version of Alpine Linux docker image
|
|
|
|
|
2020-12-12 21:54:08 +00:00
|
|
|
build_job:
|
|
|
|
stage: build
|
2020-07-05 10:46:19 +00:00
|
|
|
|
|
|
|
before_script:
|
2021-05-04 08:04:37 +00:00
|
|
|
- apk update && apk add curl openssh-client git grep xmlstarlet
|
2020-07-05 10:46:19 +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:
|
|
|
|
- sh src/script.sh
|
|
|
|
|
|
|
|
- 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
|
|
|
|
- sh src/commit.sh
|
|
|
|
|
|
|
|
# Generate successful status badge
|
|
|
|
- mkdir -p .gitlab/
|
|
|
|
- sh src/badge.sh "success"
|
|
|
|
- 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
|
|
|
|
- git remote set-url origin git@gitlab.com:curben/phishing-filter.git
|
2020-07-05 11:08:52 +00:00
|
|
|
- git push origin master
|
2020-07-05 10:46:19 +00:00
|
|
|
|
|
|
|
rules:
|
2020-12-12 21:54:08 +00:00
|
|
|
# Only trigger through schedule job and "Run pipeline" in master branch
|
|
|
|
- if: '$CI_COMMIT_REF_NAME == "master" && ($CI_PIPELINE_SOURCE == "schedule" || $CI_PIPELINE_SOURCE == "web")'
|
2020-07-05 10:46:19 +00:00
|
|
|
when: always
|
|
|
|
|
|
|
|
# Upload working folder as a job artifact
|
|
|
|
artifacts:
|
|
|
|
paths:
|
|
|
|
- tmp/
|
2021-03-18 16:21:48 +00:00
|
|
|
expire_in: 30 days
|
2020-07-05 10:46:19 +00:00
|
|
|
|
2020-12-12 21:54:08 +00:00
|
|
|
deploy_job: # Trigger deploy job on curben/phishing-filter-mirror
|
|
|
|
stage: deploy
|
|
|
|
trigger:
|
|
|
|
project: curben/phishing-filter-mirror
|
|
|
|
branch: master
|
|
|
|
strategy: depend
|
|
|
|
rules:
|
|
|
|
- if: '$CI_COMMIT_REF_NAME == "master" && ($CI_PIPELINE_SOURCE == "schedule" || $CI_PIPELINE_SOURCE == "web")'
|
|
|
|
when: always
|
|
|
|
|
2020-07-05 10:46:19 +00:00
|
|
|
failed_job:
|
|
|
|
stage: failed_stage
|
|
|
|
|
|
|
|
before_script:
|
|
|
|
- 'which ssh-agent || (apk update && apk add curl openssh-client git grep)'
|
|
|
|
- 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/
|
|
|
|
- sh src/badge.sh "failed"
|
|
|
|
- git add .gitlab/status.svg
|
|
|
|
- git diff-index --quiet HEAD || git commit -m "Failed pipeline"
|
|
|
|
- ssh -T git@gitlab.com
|
|
|
|
- git remote set-url origin git@gitlab.com:curben/phishing-filter.git
|
2020-07-05 11:08:52 +00:00
|
|
|
- git push origin master
|
2020-07-05 10:46:19 +00:00
|
|
|
|
|
|
|
rules:
|
2020-12-12 21:54:08 +00:00
|
|
|
- if: '$CI_COMMIT_REF_NAME == "master" && ($CI_PIPELINE_SOURCE == "schedule" || $CI_PIPELINE_SOURCE == "web")'
|
2020-07-05 10:46:19 +00:00
|
|
|
# Run this job only when deploy_job failed
|
|
|
|
when: on_failure
|