Devops Project 2 Develop Jenkins Pipeline Project
Devops Project 2 Develop Jenkins Pipeline Project
Devops Project 2 Develop Jenkins Pipeline Project
Jenkins Pipeline (or simply "Pipeline") is a suite of plugins which supports implementing and
integrating continuous delivery pipelines into Jenkins.
A continuous delivery pipeline is an automated expression of your process for getting software
from version control right through to your users and customers.
Jenkins Pipeline provides an extensible set of tools for modeling simple-to-complex delivery
pipelines "as code". The definition of a Jenkins Pipeline is typically written into a text file (called
a Jenkinsfile) which in turn is checked into a project’s source control repository. [1]
For more information about Pipeline and what a Jenkinsfile is, refer to the
respective Pipeline and Using a Jenkinsfile sections of the User Handbook.
After you have setup your Pipeline, Jenkins will automatically detect any new Branches or Pull
Requests that are created in your repository and start running Pipelines for them.
Java
pipelin
e {
agent any
environment {
//be sure to replace "bhavukm" with your own Docker Hub username
DOCKER_IMAGE_NAME = "bhavukm/train-schedule"
}
stages {
stage('Build') {
steps {
echo 'Running build automation'
sh './gradlew build --no-daemon'
archiveArtifacts artifacts: 'dist/trainSchedule.zip'
}
}
stage('Build Docker Image') {
when {
branch 'master'
}
steps {
script {
app = docker.build(DOCKER_IMAGE_NAME)
app.inside {
sh 'echo Hello, World!'
}
}
}
}
stage('Push Docker Image') {
when {
branch 'master'
}
DevOps Project 2 Develop Jenkins Pipeline Project
steps {
script {
docker.withRegistry('https://registry.hub.docker.com',
'docker_hub_login') {
app.push("${env.BUILD_NUMBER}")
app.push("latest")
}
}
}
}
stage('CanaryDeploy') {
when {
branch 'master'
}
environment {
CANARY_REPLICAS = 1
}
steps {
kubernetesDeploy(
kubeconfigId: 'kubeconfig',
configs: 'train-schedule-kube-canary.yml',
enableConfigSubstitution: true
)
}
}
stage('DeployToProduction') {
when {
branch 'master'
}
environment {
CANARY_REPLICAS = 0
}
steps {
input 'Deploy to Production?'
milestone(1)
kubernetesDeploy(
kubeconfigId: 'kubeconfig',
configs: 'train-schedule-kube-canary.yml',
enableConfigSubstitution: true
)
kubernetesDeploy(
kubeconfigId: 'kubeconfig',
configs: 'train-schedule-kube.yml',
DevOps Project 2 Develop Jenkins Pipeline Project
enableConfigSubstitution: true
)
}
}
}
}
You need a Java JDK 7 or later to run the build. You can run the build like this:
./gradlew build
You can run the app with:
./gradlew npm_start
Thank You