Categories: Uncategorized

by Jerome Josephraj

Share

Creating Pipeline in Jenkins

Creating pipeline in Jenkins to run the features created in NoCodeBDD is a fairly straight forward process. This article shows how this is done step by step.

Assumption

Before setting up Jenkins, please ensure that following set-up are already done in the Jenkins box:

  • NoCodeBDD is installed and is running on http://<ip>:56244 or if NoCodeBDD is installed and running in a different server, ensure it can be accessed from the Jenkins box.
  • In NoCodeBDD, “Run headless” option is turned off (This is under Settings page as shown below)
  • Provide GIT Repo info from where NoCodeBDD should pull this info. You can provide branch name in the API script that you will be running in Jenkins, but the repo info has to be already provided in NoCodeBDD, as shown below
  • Jenkins should already be installed. This article details only about setting up NoCodeBDD in Jenkins.This article is based on Jenkins version 2.303.2, but the steps explained here should work on any of the recent Jenkins version and the APIs shared here should work with all Jenkins version.

HTML Publisher Plugin

Install HTML publisher plugin

  1. Open jenkins
  2. Select manage jenkins
  3. Click on Available plugins and search for HTML publisher
  4. Select HTML publisher plugin, install the plugin and restart jenkins

Add Environment Variable

Add environment variable

  1. Click on manage Jenkins
  2. select script console
  3. Paste the following command and run
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP","sandbox allow-scripts allow-same-origin;")

Create Pipeline

Follow these steps to create pipeline:

  1. Create pipeline
    Click on New Item as shown below:

Enter a name for your pipeline, click on pipeline and click on OK as shown below:

Click on Pipeline tab as shown in the following screen. Select any other options that may be suitable for your pipeline

You can copy the example script given under “Example Declarative Script” section and paste it in Pipeline. Also change the values like GIT_USERNAME, GIT_TOKEN, GIT_BRANCH_NAME according to your environment.

Example Declarative Script

Following sample script shows how the pipeline pulls NoCodeBDD features from GIT, runs all features and checks for status and fails the pipeline stage and the pipeline, if any of the scenario fails:

pipeline {
   agent any

   stages {
        stage('Build') {
            steps {
            echo 'Building...';
            echo "Running ${env.BUILD_ID} ${env.BUILD_DISPLAY_NAME} on ${env.NODE_NAME} and JOB ${env.JOB_NAME}";
            echo 'Check out to revert all files to head'
                sh '''curl --location --request POST \\
              http://<IP_NOCODEBDD_IS_RUNNING>:56244/git/revertAllFilesToHead \\
              -H \'cache-control: no-cache\' \\
              -H \'content-type: application/json\' \\
	      -d \'{}\' '''

            echo 'Changing the branch'
                sh '''curl --location --request POST \\
              http://<IP_NOCODEBDD_IS_RUNNING>:56244/git/changeBranch \\
              -H \'cache-control: no-cache\' \\
              -H \'content-type: application/json\' \\
	      -d \'{"branchName":"<branchName>"}\' '''

            echo 'pulling from GIT'
            sh '''curl -X POST \\
              http://<IP_NOCODEBDD_IS_RUNNING>:56244/git/pull \\
              -H \'cache-control: no-cache\' \\
              -H \'content-type: application/json\' \\
	      -d \'{"username":"<GIT_USRENAME>","password":"<GIT_TOKEN>","branchName":"<BRANCH_NAME>"}\' '''
            }
        }
        stage('Test') {
            steps {
                echo 'Testing...';
                sh 'whoami'
                
                sh '''curl -X POST \\
                    http://<IP_NOCODEBDD_IS_RUNNING>:56244/runAllFeatures \\
                    -H \'cache-control: no-cache\' \\
                    -H \'content-type: application/json\' \\
                    -d \'{"host":"http://<IP_NOCODEBDD_IS_RUNNING>:56244"}\' -o ./output/report.json'''
                publishHTML([allowMissing: false,
                    alwaysLinkToLastBuild: true,
                    keepAll: true,
                    reportDir:'output/',
                    reportFiles: 'index.html',
                    reportName: 'NoCodebdd Reports'
                    ])
            }
        }
        stage('result'){
            steps{
                script{
                    status = readFile('./output/report.json').trim()
                    echo "value = $status"
                    if("$status".contains("\"runstatus\":false")){
                        // currentBuild.result = 'FAILURE'
                
                       sh "exit 1"
                        
                    }
                }
            }
        }

        stage('Deploy') {
            steps {
            echo 'Deploying...'
            }
        }
    }
}

Following section gives information more about each of the APIs that are used in the sample script above

APIs

Following are the APIs that should be used to trigger different actions, which are required to run your features files in Jenkins:

API for GIT Pull

Use following API to pull any BDD Feature files from GIT. This is an essential API, which should be called in your pipeline step so any changes will be pulled from your BDD git repo before the feature files are run. Typically this should be called in your BUILD stage.

http://<ip>:56244/git/pull  
-H  'cache-control: no-cache'  
-H 'content-type: application/json' 
-d '{"username":"<GIT_USERNAME>","password":"<GIT_TOKEN>","branchName":"<BRANCH_NAME>"}'

RUN all bdd features

Use following API To run all features of your BDD:

http://<ip>:56244/runAllFeatures
-H 'cache-control: no-cache'
-H 'content-type: application/json' 
-d '{}' -o ./output/report.json'''

API to run all NoCodeBDD features

Reports

In order to view NoCodeBDD reports, you need to use publishHTML as shown below:

publishHTML([allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir:'output/',
reportFiles: 'index.html',
reportName: 'NoCodebdd Reports'])

Script to publish report

Copy Files

Once the pipeline is created, download the attached “NoCodeBDD_Jenkins_Files.zip” file. Then go to your Jenkins workspace director and create a directory with your pipeline name, if it doesn’t exist, and under that create another folder called output and unzip the downloaded file. Once unzipped you should see following files:

  • report.json
  • index.html
  • jquery-3.5.1.min.js

Following sample screenshot shows how and where the files are copied:

Sample screenshot of jenkins pipeline workspace

After copying files restart Jenkins

NoCodeBDD Reports

Once the above mentioned steps are completed and after the pipeline been run, NoCodeBDD report menu should be shown on the left side menu as shown below:

Sample Report

Clicking the NoCodeBDD reports should open a report page as shown below:

Running Multiple Projects

To run multiple projects in Jenkins, set up different pipeline for different projects. Follow the same steps that are described above. Each project requires its own instance of NoCodeBDD. Following steps shows a sample of how two different projects are set up. You can use this to set up any number of projects.

  1. Run NoCodeBDD instance for the first project. In order to do that, run the NoCodeBDD instance in a port of your preference as shown below. After running this command NoCodeBDD should run in port 50001 and you can check that by going to https://<ip>:50001
java -jar -Dserver.port=50001 NoCodeBDD.jar

2. Repeat the above step to run the second project in a different port. For that you could use the same command as above but change the port as shown below.
After running this command NoCodeBDD should run in port 50001 and you can check that by going to https://<ip>:50002

java -jar -Dserver.port=50002 NoCodeBDD.jar

3. Once both NoCodeBDD instances are up and running, follow the steps given in this article under “Creating Pipeline in Jenkins” heading to set up Jenkins pipeline. Each pipeline script should point to its own GIT Repo (if two different repos are used), its own GIT branch and should point to the relevant NoCodeBDD instance

Note: If you are running NoCodeBDD in docker, run two different docker container each having its own NoCodeBDD instance. You can follow the steps shown in this link to run it in Docker

https://blog.nocodebdd.com/running-nocodebdd-in-docker/

STAY IN THE LOOP

Subscribe to our free newsletter.

Related Posts

View all

  • I had the pleasure of hosting a webinar with two industry experts, Rebecca Stone from IBM. During the webinar, Rebecca shared her experience in successfully implementing BDD in a large government project, highlighting the benefits of BDD, why and how she used OOPSI and its role in overcoming challenges faced […]

    Continue reading
  • Key Considerations for Rolling Out BDD in a Project Key Considerations for Rolling Out BDD in a Project

    Rolling out BDD in a project requires careful planning and a well-structured process. As a tech consultant on a large project, I had to make several changes to their BDD process and automation suite implementation. Some changes were straightforward, while others proved more challenging. If you’re considering implementing BDD in […]

    Continue reading
  • 10 Tips for Writing Effective BDD Scenarios When rolling out BDD having a clear and concise scenario writing is a vital aspect of successful BDD adoption. This blog post will provide you with 10 tips to enhance your BDD scenario writing, making it easy to understand, maintainable, and efficient. 1. […]

    Continue reading
  • It will be difficult to automate testing if you don’t consider it when creating your web application. It will be difficult, regardless of whether you are a code wizard or a no-code ninja. Here are some crucial ideas to have in mind as you develop your app to make testing a […]

    Continue reading