- Internet Connection
- Jenkins VM
- Gitlab VM
- Nexus VM
- template engine
- pipeline-utility
- sonarqube
- docker
- gitlab
- gitlab branch sources
- multibranch-pipeline
- multibranch scan webhook trigger
- Nexus Artifact Uploader
Most pipelines are going to follow the same generic workflow regardless of which specific tech stack is employed by an application. The Templating Engine Plugin (abbreviated as JTE for Jenkins Templating Engine) allows you to capture this efficiency by creating tool-agnostic, templated workflows to be reused by every team.
- Pipeline Template
message()
deploy(dev)
deploy(prod)
- Libraries
void call() {
String nodeName = config.nodename ?: "master"
node(nodeName){
stage("Message node ${nodeName}"){
}
}
}
- Pipeline Configuration
libraries{
simple_mesagge {nodename: "master"}
}
stages{
ci{
build
unit_test
}
cd{
upload_artifact
}
}
application_environments{
dev
prod
}
pipeline {
agent any
stages {
stage('Build'){
steps{
//
}
}
stage('Test'){
steps{
//
}
}
stage('Deploy'){
steps{
//
}
}
}
}
node('master'){
stage('Build'){
//
}
}
node('master'){
stage('Test'){
//
}
}
node('master'){
stage('Deploy'){
//
}
}
node('master'){
stage('Build'){
//
}
stage('Test'){
//
}
stage('Deploy'){
//
}
}
First going to Dashboard Jenkins > New Item > Pipeline > Jenkins Template Engine
docker.image("maven").inside{
sh "mvn --version"
}
Then save and build
Login Gitlab > Profile > Access Token
Login Jenkins > Manage Jenkins > Manage Credentials > Jenkins > Global Credentials > Add Credentials > Gitlab Personal Access Token
Create directory structure like this :
.
├── simple_ansible
│ └── steps
│ └── deploy.groovy
├── simple_deploy
│ └── steps
│ └── deploy.groovy
├── simple_maven
│ └── steps
│ └── build.groovy
└── simple_sast
└── steps
└── sonarqube.groovy
- simple_maven/steps/build.groovy :
void call(){
node('master'){
stage("Maven Build"){
println "[+] Build maven library simple"
}
}
}
- simple_sast/steps/sonarqube.groovy :
void call(){
node('master'){
stage("Sonarqube Scanning"){
println "[+] Scanning source code using sonarqube simple"
}
}
}
- simple_deploy/steps/deploy.groovy :
void call(){
node('master'){
stage("Deploy"){
println "[+] Deployment simple"
}
}
}
- simple_maven/steps/unit_test.groovy :
void call(){
node('master'){
stage("Maven Unit Test"){
println "[+] Unit-test maven library simple"
}
}
}
- simple_nexus/steps/upload_artifact.groovy :
void call(){
node('master'){
stage("Upload Artifact Maven"){
println "[+] Uploading artifact maven to nexus "
}
}
}
- Then push to gitlab
Dashboard Jenkins > Manage Jenkins > Configure System > Jenkins Templating Engine > Add library sources
Dashboard jenkins > New Item > Pipeline
- Select pipeline : Jenkins Template Engine
- Select pipeline configuration : From Console
// gambar
pipeline template :
build()
unit_test()
sonarqube()
upload_artifact()
deploy()
pipeline configuration :
libraries{
simple_maven
simple_sast
simple_nexus
simple_deploy
}
Note : Stages are a mechanism for chaining multiple steps together to be invoked through an aliased method name.
pipeline template :
ci()
cd()
deploy()
pipeline configuration :
stages{
ci{
build
unit_test
}
cd{
upload_artifact
}
}
libraries{
simple_maven
simple_sast
simple_deploy
simple_nexus
}
Library :
void call(app_env) {
String nodeName = config.nodename ?: "master"
node(nodeName){
stage("Deploy to ${app_env.short_name}"){
app_env.ip_addr.each{ ip ->
println "Deploy to $ip "
}
}
}
}
pipeline template :
deploy()
pipeline configuration :
application_environments{
staging{
short_name = "Staging"
ip_addr = ["10.1.1.10" , "10.1.1.10"]
}
prod{
short_name = "production"
ip_addr = ["10.1.1.10" , "10.1.1.10"]
}
}
libraries{
simple_ansible {nodename: "master"}
}
- https://jenkinsci.github.io/templating-engine-plugin/2.5.2/
- https://boozallen.github.io/sdp-docs/learning-labs/1/index.html
Coming Soon