Why does gradle build locations differently locally and via gitlab pipelines? - gradle

Basic Spring Boot app with Gradle.
If I build locally with Gradle using
./gradlew clean build
my jar is in
build/
But when using GitLab's pipelines with the following config
gradle-build:
image: gradle:alpine
stage: build
script:
- ./gradlew clean build
artifacts:
paths:
- build/libs/*.jar
The jar is in
build/libs
The "artifacts -> paths" config is just to share the jar with the next step of the pipeline, which is building the docker container.
So why the difference between the 2 ?
I like to have consistency and have the same thing locally as on the build server.
Thanks.

Related

Gitlab CI/CD with gradle build and push to Google Artifactory Registry GCP AR

I'm building a pipeline in GitLab CI/CD with the .gitlab-ci.yml file. It's a Java application, gradle is the build too and I have to push this artifact to GCP AR.
So I'm using a gradle image and I don't know where after the build my artifact is located and the syntax I'll use to push that artifact to Google Artifact.
Below is my progress:
image: gradle:alpine
stages:
- build
- test
Build_Stage:
stage: build
script:
- gradle build
cache:
paths:
- build
- .gradle
Test_Job:
stage: test
script:
- gradle check
cache:
paths:
- build
- .gradle
after_script:
- echo "End of CI"
console output on GitLab I don't even know if it actually build a .jar and where the .jar package is at

Maven Dependency project on Google Cloud Build with SonarScanner

I will try to keep the description brief. We have a couple of projects. Some of them are full blown Spring Boot apps, some of them are Maven Dependency projects (used in those Spring Boot apps).
I have set up a Jenkins server for automating pipelines. Jenkins calls Google Cloud Build to build projects/docker images and cache dependencies. It also calls SonarQube in a step. This all works fine for the Spring Boot apps, but the SonarQube step fails for the dependency projects. The error is Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project projectname: Not inside a Git work tree: / -> [Help 1].
The Dockerfile for the project:
FROM maven:3.5-jdk-8-alpine
# Copy local code to the container image.
COPY pom.xml settings.xml ./
RUN mvn -s settings.xml dependency:go-offline
COPY src ./src
# Build a release artifact.
RUN mvn verify -DskipTests -s settings.xml
The cloudbuild.yaml:
substitutions:
_IMAGE_NAME: "projectname"
steps:
- name: "docker"
entrypoint: "sh"
args:
- "-c"
- |-
docker pull gcr.io/gcp-project/${_IMAGE_NAME}:$_TAG
docker pull gcr.io/gcp-project/${_IMAGE_NAME}:latest || true
- name: "docker"
args:
- "build"
- "-t"
- "gcr.io/gcp-project/${_IMAGE_NAME}"
- "-t"
- "gcr.io/gcp-project/${_IMAGE_NAME}:$_TAG"
- "--cache-from"
- "gcr.io/gcp-project/${_IMAGE_NAME}:latest"
- "--cache-from"
- "gcr.io/gcp-project/${_IMAGE_NAME}:$_TAG"
- "."
- name: "gcr.io/gcp-project/${_IMAGE_NAME}"
entrypoint: "bash"
args:
- "-ce"
- |-
mvn -f /pom.xml -s ./settings.xml sonar:sonar -Dsonar.host.url=https://sonar.server.com -Dsonar.login=${_SONAR_KEY}
- name: "gcr.io/gcp-project/${_IMAGE_NAME}"
args:
- "mvn"
- "deploy"
- "-s"
- "/settings.xml"
images: ["gcr.io/gcp-project/${_IMAGE_NAME}"]
There are two very confusing things. If i run the maven command locally, the analysis completes successfully. Also, if i run the local Google Cloud Build tool (cloud-build-local) it also passes.
I have verified that the .git folder is not uploaded. It is neither with the Spring Boot apps.
I copied the settings.xml from the Jenkins server locally and used that one. Neither the Spring Boot apps or the dependencies define a sonar-project.properties.
Is there anyone who can shed some light on this?
Thanks in advance!
EDIT
I created 2 repositories that are able to replicate this problem:
Non-working: https://github.com/claystation/mvnsonarapp
Working: https://github.com/claystation/mvnsonarappworking
I think the main difference is the dependency project not having #SpringBootApplication?
Ok, so i finally figured it out how to solve this, by doing the MCVE.. Unfortunately not WHY the problem exists.
The main difference between the projects was the #SpringBootApplication annotation. I thought this might have something to do with having the spring-boot-starter-parent parent defined.
I removed the parent part and now my project is passing in Sonar. If there is ever someone who can explain WHY Sonar gives this error with the parent defined but no #SpringBootApplication annotation, that would be very helpful.
Thanks!

CICD Java Application(Maven)

How can I create a Java(Maven) Application as a CICD Project on gitlab with windows and with a shell runner. Is it right manner? When I search this subject, I see a java/CICD Project or a Maven/CICD Project , but not a CICD Project where the java aplication which build within maven.
Here an example that how you can;
image: adoptopenjdk/maven-openjdk11
build:
script: "mvn clean install"

jhipster v4.14.4 - building an executable WAR-file

As mentioned here as well as here it should be possible - and a must-have for the docker-container - to be able to build a WAR-file of the whole application with ./gradlew -Pprod bootWar or make the application ready for a deployment via docker-container with ./gradlew bootWar -Pprod buildDocker.
But Intellij IDEA tells me, that there is no task bootWar. And ./gradlew -Pprod bootRundoesn't generate a *.war-file in build/libs/.
I also tried publishing directly to heroku, triggered by pushes to my github-repository controlled by a local jenkins2 docker-container. Maybe even the 404-Site after successful builds at heroku comes from this. The manual way documented in the jhipster.tech-documentation with ./gradlew -Pprod bootWar -x test and heroku deploy:jar --jar build/libs/*war can't work without the *.war.
So how can I export my monolithic jhipster-application into a *.war-file?
AFAIK you can generate a war with gradle by typing the following command
./gradlew -P prod build and/or ./gradlew -P prod build bootRepackage

Gitlab appengine:deploy missing JAR on Gitlab only

I have setup a multi module spring boot application including Google appengine integration. Locally everything works fine.
If I do a clean checkout of my GIT repo and after that execute
mvn clean install
mvn appengine:deploy
The app gets properly deployed to Google appengine
If I try to do the same on gitlab using the following deploy pipeline
deploy-prod:
stage: deploy
image: $CI_REGISTRY_IMAGE/build
when: manual
environment: prod
script:
- 'mvn clean install'
- 'mvn appengine:deploy'
I get an error saying:
Failed to execute goal on project XXX: Could not resolve dependencies
for project YYY:XXX:war:0.0.1-SNAPSHOT: Could not find artifact
YYY:XXX:jar:0.0.1-SNAPSHOT
Do you have any idea what is wrong/different here? Never had such problems on Gitlab? And I have no idea what is different to the case when I do a clean checkout locally and execute the same commands there?
Thanks for your help.
I assume, you are checking it at your local machine. But have you checked it with $CI_REGISTRY_IMAGE/build manually? I think there is an issue with the docker image itself.

Resources