Currently I've a CI pipeline with the following stages:
- Build
- Unit Tests
- Static Code Analysis
This is how my Jenkinsfile looks like:
pipeline {
agent any
stages {
stage("Install") {
steps {
sh "npm install"
}
}
stage("Build") {
steps {
sh "npm run build"
}
}
stage("Format") {
steps {
sh "npm run format"
}
}
stage("Lint") {
steps {
sh "npm run lint"
}
}
stage("Test") {
steps {
sh "npm run test"
}
}
stage("Code Coverage") {
steps {
sh "npm run test:cov"
publishHTML(target: [
reportDir: "./coverage/lcov-report",
reportFiles: "index.html",
reportName: "Jest Coverage Report"
])
}
}
stage("End-To-End Testing") {
steps {
sh "npm run test:e2e"
}
}
}
}
I want to add more stages to my pipeline:
- Build and tag Docker Image from Dockerfile
- Push the image to the Docker Hub
- Some more steps which would need Docker CLI
Example:
pipeline {
.
.
.
stage("Docker Build") {
steps {
sh "docker build -t [user_name]/[image_name]:[tag] .
}
}
}
I'm quite new to this, and I have tried multiple ways to install docker and it was unsuccessful and it is a bad practice too.
We can run docker run -v /var/run/docker.sock:/var/run/docker.sock ... but I can't use bind mounting while using docker build command.
Can someone please suggest me a way where I can use docker commands inside Jenkins SSH Agents?