Skip to content
Snippets Groups Projects

Tut01 test exercise

Closed Yana Kernerman requested to merge s92604/devops-webservice:tut01 into main
1 file
+ 30
30
Compare changes
  • Side-by-side
  • Inline
+ 57
7
workflow:
rules:
- if: >-
$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"
when: 'always'
- when: 'never'
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: always
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"
when: always
- when: never
stages:
- test
- build
- publish
job_trigger-pipeline:
trigger:
project: 'fb6-wp11-devops/webservice-build-and-publish'
job_test_the_code:
stage: test
image: registry.hub.docker.com/library/golang:1.21
script:
- go get -t ./...
- go test -race -v ./...
rules:
- when: always
job_build_artifact:
stage: build
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME =~ /main/
when: always
image: registry.hub.docker.com/library/golang:1.21
script:
- go get -t ./...
- go build -o ./artifact.bin ./*.go
artifacts:
paths:
- ./artifact.bin
expire_in: 1 week
job_publish_artifact:
stage: publish
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME =~ /main/
when: always
image: curlimages/curl:latest
tags:
- docker-privileged
dependencies:
- job_build_artifact
script:
- echo "Publishing artifact..."
- ls -al
- pwd
- echo "${CI_JOB_TOKEN}"
- echo " ${CI_API_V4_URL}"
- echo "${CI_PROJECT_ID}"
- echo "${CI_COMMIT_REF_NAME}"
- echo "${version}"
- curl --version
- |
curl \
--header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
--upload-file ./artifact.bin \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/artifacts/1.0.0/webservice"
Loading