Skip to content
Snippets Groups Projects
Commit d0f28c60 authored by Yana Kernerman's avatar Yana Kernerman
Browse files

Merge branch 'tut01' into 'main'

Tut01 test exercise

See merge request s92604/devops-webservice!3
parents 57901d91 1335f6c4
No related branches found
No related tags found
1 merge request!3Tut01 test exercise
Pipeline #69700 failed
workflow:
# rules:
# - if: $CI_PIPELINE_SOURCE == "merge_request_event"
# when: 'always'
# - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME =~/main/
# - when: 'never'
stages: stages:
- test - test
- build - build
- publish - publish
# Main job to test the application
job_test_the_code: job_test_the_code:
stage: test stage: test
image: registry.hub.docker.com/library/golang:1.21 # Official Docker image provided by Go. It contains pre-configured environment for building and running Go applications. image: registry.hub.docker.com/library/golang:1.21
script: script:
- go get -t ./... # Installs dependencies, including those for testing - go get -t ./...
- go test -race -v ./... # Run tests with race detection enabled - go test -race -v ./...
rules:
- when: always
job_build_artifact: job_build_artifact:
stage: build stage: build
# rules: # Conditions under which this job should run rules:
# - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" # Run this job only for merge request event into main. - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"
# when: always when: always
image: registry.hub.docker.com/library/golang:1.21 image: registry.hub.docker.com/library/golang:1.21
script: script:
- go get -t ./... # Installs dependencies - go get -t ./...
- go build -o ./artifact.bin ./*.go # Builds the Go application and outputs a binary named artifact.bin - go build -o ./artifact.bin ./*.go
artifacts: artifacts:
paths: # Specifies the paths to the files that are to be saved as artifacts after the job has been completed. paths:
- ./artifact.bin - ./artifact.bin
expire_in: 1 week expire_in: 1 week
job_build_and_publish_image: job_publish_artifact:
stage: publish stage: publish
# rules: # Conditions under which this job should run rules:
# - if: $CI_PIPELINE_SOURCE == "push" && $CI_MERGE_COMMIT_REF_NAME =~ /main/ # Run this job only for merge request event into main. - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME =~ /main/
# when: always when: always
image: docker:24.0.0 # Official Docker image with Docker client installed image: curlimages/curl:latest
services:
- docker:24.0.0-dind # used to access the Docker daemon from within the CI job.
tags: tags:
- docker-privileged - docker-privileged
dependencies: dependencies:
- job_build_artifact - job_build_artifact
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
script: script:
- echo "Publishing artifact ..." - echo "Publishing artifact..."
- ls -al - ls -al
- TAG=$CI_COMMIT_REF_SLUG - pwd
- docker build --file ./Dockerfile --tag "$CI_REGISTRY_IMAGE:$TAG" . - echo "${CI_JOB_TOKEN}"
- docker push "$CI_REGISTRY_IMAGE:$TAG" - echo " ${CI_API_V4_URL}"
\ No newline at end of file - 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"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment