Script: How to write a bash script to run CI pipeline commands for development?

Akarsh Seggemu, M.Sc.
2 min readJun 3, 2023

--

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),

  1. Build
  2. 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.

Console output of running build and test stages in example-project via init.sh bash script file

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)

--

--

Akarsh Seggemu, M.Sc.
Akarsh Seggemu, M.Sc.

Written by Akarsh Seggemu, M.Sc.

IT Team Lead | Post graduate Computer Science from TU Berlin | Telugu writings are found in this account https://medium.com/@akarshseggemu_telugu

No responses yet