#90daysofdevops #28:Jenkins Declarative Pipeline with Docker
docker build - you can use sh 'docker build . -t <tag>'
in your pipeline stage block to run the docker build command. (Make sure you have docker installed with correct permissions.
docker run: you can use sh 'docker run -d <image>'
in your pipeline stage block to build the container.
How will the stages look
stages {
stage('Build') {
steps {
sh 'docker build -t trainwithshubham/django-app:latest'
}
}
}
Task-01
- Create a docker-integrated Jenkins declarative pipeline.
Launch two EC2 Instances.
1.Jenkins Master
2.Jenkins Agent
Installing Java and Jenkins in Both Instances
https://goutamdevops.hashnode.dev/java-jenkins-installation
Jenkins Master Configuration
Setup of Jenkins_Agent
Manage credential
Jenkinsfile (Declarative Pipeline)
pipeline {
agent any
stages {
stage('Build') {
steps {
//
}
}
stage('Test') {
steps {
//
}
}
stage('Deploy') {
steps {
//
}
}
}
}
Jenkinsfile (Scripted Pipeline)
node {
stage('Build') {
//
}
stage('Test') {
//
}
stage('Deploy') {
//
}
}
Jenkinsfile (Declarative Pipeline)
pipeline {
agent any
options {
skipStagesAfterUnstable()
}
stages {
stage('Build') {
steps {
sh 'make'
}
}
stage('Test'){
steps {
sh 'make check'
junit 'reports/**/*.xml'
}
}
stage('Deploy') {
steps {
sh 'make publish'
}
}
}
}
| |
| |
| |
| |
| |
| |
|
Jenkinsfile (Declarative Pipeline)
pipeline {
agent { label any }
stages {
stage('code') {
steps {
git url: 'https://github.com/devkrgoutam/node-todo-cicd.git',branch:'master'
}
}
stage('build & test') {
steps {
sh 'docker build . -t node-todo-app'
}
}
stage('deploy') {
steps {
sh 'docker-compose down && docker-compose up'
}
}
}
}
pipeline {
agent { label 'goutam-node-todo-cicd'}
stages {
stage('code') {
steps {
git url: 'https://github.com/devkrgoutam/node-todo-cicd.git',branch:'master'
}
}
stage('build & test') {
steps {
sh 'docker build . -t node-todo-app'
}
}
stage('deploy') {
steps {
sh 'docker-compose down && docker-compose up -d'
}
}
}
}
Manage Jenkins-->Install Plugins-->Enviornment Injector
Jenkins Agent Configuration
Installation of docker : sudo apt-get install docker.io
Installation of docker-compose : sudo apt-get install docker –compose
Addition of docker to user : sudo usermod –aG docker Jenkins/$USER
Reboot the System: sudo reboot