Skip to content

Commit

Permalink
Update .gitlab-ci.yml and use it in branches
Browse files Browse the repository at this point in the history
  • Loading branch information
leojonathanoh committed Sep 16, 2023
1 parent d9c5ffe commit 8033a43
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 62 deletions.
31 changes: 17 additions & 14 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
stages:
- build
- post-build
- notify

build-image:
stage: build
Expand All @@ -10,15 +10,16 @@ build-image:
# For stateful builds (i.e. DOCKER_HOST=unix:///var/run/docker.sock mounted from the host), a sidecar dockerd service is not needed
# services:
# - docker:20.10.18-dind
rules:
- if: $CI_PIPELINE_SOURCE == "trigger"
- if: $CI_PIPELINE_SOURCE == "web"
variables:
DOCKER_DRIVER: overlay2
rules:
# Run on all branches except master, when .trigger is added or modified
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH != "master"
changes:
- .trigger
timeout: 120m
script:
- |
export PIPELINE="$CI_COMMIT_BRANCH"
set +e
./build.sh
if [ $? = 0 ]; then
Expand All @@ -28,20 +29,22 @@ build-image:
exit 1
fi
artifacts:
name: .build.state-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHA
paths:
- .build.state
when: always
expire_in: never

send-notification:
stage: post-build
image: alpine:3.14.8
notify:
stage: notify
image: alpine:3.15
rules:
- if: $CI_PIPELINE_SOURCE == "trigger"
- if: $CI_PIPELINE_SOURCE == "web"
# Run on all branches except master, when .trigger is added or modified
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH != "master"
changes:
- .trigger
when: always
timeout: 5m
script:
- |
apk add --no-cache curl
export X_CI_WEBHOOK_SECRET_HEADER="x-gitlab-webhook-secret: $X_GITLAB_WEBHOOK_SECRET"
./notify.sh
- apk add --no-cache curl
- ./notify.sh
50 changes: 2 additions & 48 deletions Generate-GitBranches.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ try {
if ($LASTEXITCODE) { throw }
git checkout master -- notify.sh
if ($LASTEXITCODE) { throw }
git checkout master -- .gitlab-ci.yml
if ($LASTEXITCODE) { throw }

@"
PIPELINE=build
Expand All @@ -95,54 +97,6 @@ BASE_SIZE=0
LAYERED_SIZE=0
'@ | Out-File .state -Encoding utf8 -Force

@'
stages:
- build
- notify
build-image:
stage: build
image: docker:20.10.18-git
services:
- docker:20.10.18-dind
variables:
DOCKER_DRIVER: overlay2
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH != "master" # Run on all branches except master
changes:
- .trigger # Run only when .trigger is added or modified
timeout: 120m
script:
- |
set +e
./build.sh
if [ $? = 0 ]; then
echo BUILD_STATUS=success >> .build.state
else
echo BUILD_STATUS=failed >> .build.state
exit 1
fi
artifacts:
name: .build.state-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHA
paths:
- .build.state
expire_in: never
when: always
notify:
stage: notify
image: alpine:3.15
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH != "master" # Run on all branches except master
changes:
- .trigger # Run only when .trigger is added or modified
when: always
timeout: 60m
script:
- apk add --no-cache curl
- ./notify.sh
'@ | Out-File .gitlab-ci.yml -Encoding utf8 -Force

git add .
if ($existingBranch) {
git commit -m "Update files"
Expand Down

0 comments on commit 8033a43

Please sign in to comment.