Prerequisite: For testing purpose, we can setup Jenkins, GitLab server with Docker. Ref: Jenkin Install With Gitlab using Docker
Go to Manage Jenkins > Manage Plugins.
- GitLab Plugin
- Git plugin (if not already installed)
Manage Jenkins -> Tools : Select Install automatically - We can install one or more JDK version
JDK(s) https://jdk.java.net/archive/
Other option: We can install JDK directly on Jenkins machine (but this way is not convenient because it will apply for all jenkins jobs). Ex: sudo apt install openjdk-8-jdk
Maven setup: Manage Jenkins -> Tools -> Go to Maven section
- Create a new Access Token on Gitlab -> Copy it
- On Jenkins
- Manage Jenkins -> Credentials -> Create a new credentials (type: Secret text)
- Create Gitlab connection on Jenkins (using above credential): Manage Jenkins -> System -> Find GitLab section
Setup Credential to connect to Git to fetch source code
Manage Jenkins -> Credentials -> Select Kind as Username and Password -> Input username and password from Gitlab
(Note: We can setup ssh in jenkins machine and put it to Gitlab, then config ssh credential instead)
Create a new Job
Note: Url Repository (like container.network_name), not using expose port because we connect from jenkin machine to gitlab server with same network (inside docker)
For Build Step
Select Maven version you already setup and command to build your project (depend on your project)
Finish for freestyle project
https://www.jenkins.io/doc/book/pipeline/
Jenkins Pipeline (or simply "Pipeline" with a capital "P") is a suite of plugins which supports implementing and integrating continuous delivery pipelines into Jenkins.
Pipeline domain-specific language (DSL) syntax.
"While the syntax for defining a Pipeline, either in the web UI or with a Jenkinsfile is the same, it is generally considered best practice to define the Pipeline in a Jenkinsfile and check that in to source control."
Creating a Jenkinsfile and committing it to source control Create and configure a Pipeline project through a Jenkinsfile or through Blue Ocean
- Add cred
https://www.jenkins.io/doc/book/using/using-credentials/
- Pipeline
Jenkins is, fundamentally, an automation engine which supports a number of automation patterns.
- Create Jenskinfile
text file that contains the definition of a Jenkins Pipeline and is checked into source control
https://www.jenkins.io/doc/book/pipeline/jenkinsfile/
https://github.com/giaule91/spring-boot-demo/blob/main/simple-demo/Jenkinsfile
https://devopspilot.com/content/jenkins/tutorials/pipeline/02-how-to-write-jenkinsfile.html
agent any
stages {
stage('Build') {
steps {
mvn compile jib:build
}
}
stage('Test') {
steps {
echo 'Testing..'
}
}
stage('Deploy') {
steps {
ssh r
remote 126.55.255.33
docker run <dsdds>
}
}
}
}