Script: How to write a bash script to run CI pipeline commands for development?
In my previous post — CI: How to run docker test on a Node.js project in Jenkins? we have the docker commands arranged in the two stages in CI (Jenkins),
- Build
- Test
The Jenkinsfile of the Node.js project
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git branch: 'main', changelog: false, poll: false, url: 'https://github.com/akarsh/Selenium-WebDriver-CucumberJS-example-project.git'
}
}
stage('Build') {
steps {
sh '''
docker build -t example-project --target test .
'''
}
}
stage('Run test') {
steps {
sh'''
docker run --rm --name cucumber-test example-project
'''
}
}
}
}
How about we are able to run the two stages in development when we are working on a local branch?
This can be achieved by adding the two docker commands in a bash script file.
Create a bash script file and name it as init.sh
and add the commands from the two stages,
The bash script for development purpose of the Node.js project
#!/bin/bash
# Build
docker build -t example-project --target test .
#Test
docker run --rm --name cucumber-test example-project
Run the bash script file using the following command,
sh init.sh
It will execute the two commands locally in the terminal.
Note: Make sure DockerDesktop app is running before running the bash script.
I hope my article helps you understand how to write a bash script to run CI pipeline commands for development.
If you like my articles, please follow me on Medium and you can also support me by [buying me a coffee.](https://www.buymeacoffee.com/akarshseggemu)