Professional Documents
Culture Documents
Jenkins Declarative Pipeline Creation
Jenkins Declarative Pipeline Creation
Goals:
Stages:
Assigned by Vijay :
Solution:
Page | 1
Architecture Diagram
Installations Required
First we have taken two Centos Servers in AWS with t3.medim computer power and 8gb of
storage.. Allowed Jenkins port 8080 and in sonar&nexus instance allowed port for sonar and
nexus that is 8081 and 8080 ,9000 for sonar & in another instance.
Page | 2
Installed Jenkins in Jenkins server
Page | 3
Now Jenkins server is up and running .. Lets move to another server that is sonar&Nexus server
wget https://download.sonatype.com/nexus/oss/nexus-2.14.18-01-bundle.tar.gz
Page | 4
Goto jekins host
Page | 5
With help of Jenkins snippet generator generate the declarative jekins code
Page | 6
Stage 1 pulling the code from Github
stages {
stage('PullCodeFromGitHub') {
steps {
We are using checkout from version control in snippet generator to script as shown in fig below
Page | 7
Copy the generated code to stage
stage('test') {
steps {
sh 'mvn test'
stage('package') {
steps {
Page | 8
Stage 3 QA test using SonarQube
Install sonarqube..
https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-6.7.7.zip
stage('nexusupload') {
Page | 9
steps {
Using nexus artifact upload uloader in snipper generator generated the above script as shown
below
Page | 10
Artifacts stored in releases folder as shown in pic below
Page | 11
Page | 12
Just copy the generated script and add to job in stage
….
Page | 13
Start your tomcat server
Page | 14
Login to tomcat
Page | 15
Stage 6 Notify to slack Group
Generated using snippted
Page | 16
Click advance
Page | 17
Finally received notification on slack about job status….
Page | 18
Jenkins CI
Step 1
In your Jenkins dashboard, click on Manage Jenkins from the left navigation.
Page | 19
Step 2
Click on Manage Plugins and search for Slack Notification in the Available tab. Click the
checkbox and install the plugin.
Step 3
After it's installed, click on Manage Jenkins again in the left navigation, and then go
to Configure System. Find the Global Slack Notifier Settings section and add the following
values:
The other fields are optional. You can click on the question mark icons next to them for
more information. Press Save when you're done.
Page | 20
Note: Please remember to replace the Integration Token in the screenshot below with your
own.
Step 4
For each Project that you would like receive notifications for, choose Configure from the
project's menu.
Page | 21
Step 5
Then you'll need to add Slack Notifications to the Post-build Actions for this project.
Step 6
In the Slack Notifications section, choose the events you'd like to be notified about.
expand
Previous Setup Instructions (v2.1 and lower)
Here are the instructions for installing older versions of the Slack Notifier.
Integration Settings
Post to Channel
Notifications that come in from Jenkins CI will be posted here.
team-updates
or create a new channel
Token
This token is used as the key to your Jenkins CI integration.
Regenerate
Page | 22
Jenkins Pipeline script
pipeline {
agent any
stages {
stage('PullCodeFromGitHub') {
steps {
stage('test') {
steps {
sh 'mvn test'
stage('package') {
steps {
stage('sonartest') {
steps {
Page | 23
}
stage('nexusupload') {
steps {
stage('Tomcat') {
steps {
stage('notifyonslack') {
steps {
Page | 24
Stage view
Page | 25