Gitlab ci - differences in artifacts app jar - spring-boot

My dockerfile:
FROM openjdk:8u201-jdk-alpine3.9
ADD target/app-snapshot-0.0.1.jar .
In gitlab-ci runner, during maven building process:
maven:
image: maven:3-jdk-8
stage: maven
script:
- "mvn clean package -e"
artifacts:
name: "app-snapshot"
paths:
- ./target/app-snapshot-0.0.1.jar
build:
stage: build
script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- BUILD_IMAGE_NAME=$CI_REGISTRY_IMAGE:`echo "$CI_COMMIT_REF_NAME" | tr /# _`
- docker build --pull --force-rm=true -t "$BUILD_IMAGE_NAME" .
- docker push "$BUILD_IMAGE_NAME"
But, when I used docker image after commits, changes etc., still I see first application .jar, without changes.
Where is my mistake? I would like to see - after building process - all my changes in artifacts jar app.

I can't replicate the problem, but have some ways to "solve":
Try to fix the indentation:
maven:
image: maven:3-jdk-8
stage: maven
script:
- "mvn clean package -e"
artifacts:
name: "app-snapshot"
paths:
- ./target/app-snapshot-0.0.1.jar
Use patterns in artifacts: (It is good for when versions change you not need to change the code)
.gitlab-ci.yml:
artifacts:
name: "app-snapshot"
paths:
- target/*.jar
Dockerfile:
FROM openjdk:8u201-jdk-alpine3.9
ADD target/*.jar .
Use dependencies docs:
In you build job define dependencies from maven:
build:
stage: build
script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- BUILD_IMAGE_NAME=$CI_REGISTRY_IMAGE:`echo "$CI_COMMIT_REF_NAME" | tr /# _`
- docker build --pull --force-rm=true -t "$BUILD_IMAGE_NAME" .
- docker push "$BUILD_IMAGE_NAME"
dependencies:
- maven
Is a good practice use artifacts:expire docs
.gitlab-ci.yml:
artifacts:
name: "app-snapshot"
expire_in: 15 min #Just a example
paths:
- target/*.jar

Related

Gitlab CI/CD: Publishing the result of build stage onto another stage

I'm building a CI/CD pipeline with Gitlab CI/CD.
.gitlab-ci.yml -
build:
image: node:16-alpine
stage: build
script:
- yarn install
- yarn build
artifacts:
paths:
- //something here
I have a build job which builds the app. In the next job when deploying the app, I need the build directory from the previous job that is build.
How to I publish this as an artifact?
I`m do
needs:
- job: "build"
artifacts: true
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest #docker image
script:
- echo "release job"
release:
name: 'Release Executables $CI_COMMIT_SHORT_SHA'
description: 'Created using the release-cli'
tag_name: '$CI_COMMIT_SHORT_SHA'
assets:
links:
- name: 'comment one'
url: 'https://my.gitlab.my/you/project/-/jobs/${GE_JOB_ID}/artifacts/path to file'
result search Release!

gitlab CI/CD not cache maven dependencies

I am new to Gitlab CI/CD, I have setup a simple pipeline to run jobs for a maven project when merge request is sent. here is the merged content for the pipeline:
---
stages:
- ".pre"
- pre-merge
- build-artifact
- unit-test
- build-image
- tag-image
- deploy
- ".post"
compile:
stage: pre-merge
script:
- mvn $MAVEN_CLI_OPTS compile
only:
- merge_requests
build:
stage: build-artifact
script:
- mvn $MAVEN_CLI_OPTS clean package
artifacts:
untracked: false
expire_in: 1 days
paths:
- target/*.jar
only:
- main
unit-test:
stage: unit-test
script:
- mvn $MAVEN_CLI_OPTS clean test
only:
- merge_requests
- main
build-image:
stage: build-image
script:
- echo build image using docker and publish it to artifactory
only:
- main
deploy-to-dev:
stage: deploy
script:
- update the argocd direcotry
environment:
name: development
only:
- main
tag-image:
stage: tag-image
script:
- re-tag the image and publish
only:
- tags
deploy-to-pr:
stage: deploy
script:
- update the argocd direcotry
environment:
name: production
only:
- tags
default:
tags:
- maven
variables:
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository
-Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
MAVEN_CLI_OPTS: "--batch-mode"
HELM_CHART: my-chart
cache:
paths:
- ".m2/repository"
However, seems like the cached repository is not used. I can see maven is download all the dependencies again in compile and 'unit-test' jobs. (I know I can just use the verify but I just want to test the cache in Gitlab CI)
My Setup:
Runner is using kubernetes executor
Runner is using image maven:3.8.6-openjdk-11-slim
I have exec to the runner pod and confirm that the .m2/repository is populated with jars.
no shared cache, only local

Generate plantuml pdfs GitLab CICD

I have a maven project. Inside it I have a _models/ folder where I have some .puml files.
I would like to generate the .pngs from those plantuml files each time I commit.
This is my .gitlab-ci.yml
stages:
- test
- build
- uml
.maven:
image: maven:3.6.3-jdk-11
test:
extends: .maven
script:
- mvn test
build:
extends: .maven
script:
- mvn package -B
uml:
image: miy4/plantuml
script:
- plantuml -charset UTF-8 ./_models/sequence_diagram.puml
- plantuml -charset UTF-8 ./_models/class_diagram.puml
- plantuml -charset UTF-8 ./_models/object_diagram.puml
The pipeline passes but the diagrams.png are not created in the _models folder. Do you know why?
In the GitLab pipelines it says: No diagram found but when I run locally those commands everything works fine
Thanks :)

How can I configure the .gitlab-ci.yml for Maven tests

I'm newer in GitLab. I have some tests and I want to run them by CI\CD. Can you help me to configure my .yml.
I should run testng.xml
This is my project:
enter image description here
path to my tests is: src/test/java/tests/"files with tests"
my .yml file:
image: maven:3-jdk-7
build:
script: mvn install -b
I think this should work.gitlab docs
test:
image: xxxx/xxx-test:latest
stage: test
script:
- pwd
- mvn test

Gitlab CI - Publish Failed Test Results to Pages

I'm creating a simple java project using Gradle which generates a test report (i.e. BDD Cucumber, JUnit, etc.). This project is deployed to Gitlab where the project is built as part of the Gitlab CI process.
My JUnit reports are generated in the folder build/reports/tests/test/ relative to the project path (as an index.html and some CSS files, etc.).
How do I configure my .gitlab-ci.yml to publish the content of build/reports/tests/test/ to the Gitlab Pages even after my test cases fail?
This is what I have in my .gitlab-ci.yml: (My repo can be found HERE)
Version 1: Doesn't publish anything to pages
image: java:8-jdk
stages:
- test
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
test:
stage: test
script:
- mkdir public
- ./gradlew test
artifacts:
paths:
- build/reports/tests/test/
only:
- master
after_script:
- mv build/reports/tests/test/* public
Version 2: Doesn't execute the deploy stage since test has failed.
image: java:8-jdk
stages:
- test
- deploy
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
test:
stage: test
script:
- ./gradlew test
artifacts:
paths:
- build/reports/tests/test/
pages:
stage: deploy
dependencies:
- test
script:
- mkdir public
- mv build/reports/tests/test/* public
artifacts:
paths:
- public
only:
- master
I solved the issue by adding the when: always at the end of my pages stage. It now executes the stage regardless of exit code from the dependent stage.

Resources