jenkins job for protractor cucumber - jenkins

I have a protractor cucumber intellij project. I want to create a jenkins job that can run my tests. I have no idea how to do it. I could not find any tutorials that explain where to start from. Do I need to install a plugin or what exactly?

If you are able to successfully run from CLI now, Creating a Jenkins Job should be cake walk
Step 1 - Create a new job in Jenkins with build step as - execute shell
To make life easy you can also install this plugin
Step 2: Assuming you are running the cucumber - protractor tests by configuring the cucumber as custom framework and providing the specs from conf.js like below
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
cucumberOpts : {
require : './features/LoginDefinitions.js',
format : 'pretty'
}
Step 3- Create a .bat file to trigger protractor -cucumber tests and point this batch file from Jenkins job
echo 'started execution'
protractor protractor.conf.js
//In Jenkins execute shell build step
C:\<<path>>\startExecution.bat

Related

JUnit tests failing in Jenkins with IllegalStateException

I'm running some JUnit5 tests in Jenkins, using a freestyle job and a Jenkins pipeline. These tests run fine using gradlew locally.
The pipeline groovy script (Jenkinsfile) uses
sh './gradlew clean test'
The code checks out fine and I see the Welcome to Gradle 5.5.1! message
Then, all of the tests which run fine locally with gradlew clean test fail with:
15:50:22
uk.co.motests.mfldirect.tests.UploadDataTest >
dropDownsAreDisplayed() FAILED
15:50:22 java.lang.IllegalStateException
Any idea where / how to start debugging this? This is literally the first time I've tried to run using a groovy pipeline script.
I'm posting this in the hope there is a common, beginners mistake that crops up frequently. I can post further details of the groovy file if required.
To print tests' stdout and stacktrace, enable Gradle INFO logging with sh './gradlew clean test -i'
To view DEBUG logging use sh './gradlew clean test -d'
All this data is already present in ./build/test-results/test/*.xml so you could browse the workspace of the failed Jenkins job.

Fail Jenkins build when xUnit tests do not pass

I have Jenkins building my C# .NET Core api project. I added some xUnit tests and included a powershell script inside of my Jenkins build with the "dotnet test" command to execute the tests.
That all works well and the tests are run and i can see the output in the Jenkins console.
The problem is that if i have failing tests nothing happens - jenkins goes merrily along and finished up the build process and reports it as a success.
How can i get it to fail the build?
Is there a response from the 'dotnet test' command?
I know there are xUnit Jenkins plugins but they all seem to revolve around "display the results of xUnit tests". Which is not really what i am after. I want to ACT on the results of the tests, not just see them in fancy html.
You should check for the return code from dotnet test command. It returns 0 if all tests were successful and 1 if any of the tests failed. Unfortunately it's not documented but was confirmed in this issue

protractor integration with jenkins

I need some help in integrating protractor code with Jenkins. I am new to Jenkins so i am not sure if Jenkins or Cruise Control is right as currently we have builds in Cruise Control but we are okay to migrate to Jenkins if that is better. Can someone please help me with any tutorials to link my protractor task with Jenkins or Cruise Control?
Currently we are using Gulp as a wrapper over Javascript code for execution.
We are running it with command Gulp test --site folder name
Should i just specify this command in Execute shell script option of Jenkins?
Yes, running Protractor tests from any CI tool is not complicated
Step 1:Just configure your cruise control/Jenkins job with "Execute Shell" as build step
Step 2: Depending on your choice of running tests .. create a bat file
echo Protractor Execution
Protractor protractor.conf.js // In case running with protractor
npm run --e2etests // In case running with npm run config in package.json
Gulp test --site folder name // In your case
echo Over and out.
Step 3: Point your job build step to trigger the batch file
I got this one worked out. It is working fine when i enter protractor command in Jenkins directly.
I am having some issues with gulp command in jenkins but i will open a seperate thread on that.

Execute a script from jenkins pipeline

I have a jenkins pipeline that builds a java artifact,
copies it to a directory and then attempts to execute a external script.
I am using this syntax within the pipeline script to execute the external script
dir('/opt/script-directory') {
sh './run.sh'
}
The script is just a simple docker build script, but the build will fail
with this exception:
java.io.IOException: Failed to mkdirs: /opt/script-directory#tmp/durable-ae56483c
The error is confusing because the script does not create any directories. It is just building a docker image and placing the freshly built java artifact in that image.
If I create a different job in jenkins that executes the external script as
its only build step and then call that job from my pipeline script using this syntax:
build 'docker test build'
everything works fine, the script executes within the other job and the pipeline
continues as expected.
Is this the only way to execute a script that is external to the workspace?
What am I doing wrong with my attempt at executing the script from within
the pipeline script?
The issue is that the jenkins user (or whatever the user is that runs the Jenkins slave process) does not have write permission on /opt and the sh step wants to create the script-directory#tmp/durable-ae56483c sub-directory there.
Either remove the dir block and use the absolute path to the script:
sh '/opt/script-directory/run.sh'
or give write permission to jenkins user to folder /opt (not preferred for security reasons)
Looks like a bug in Jenkins, durable directories are meant to store recovery information e.g. before executing an external script using sh.
For now all you can do is make sure that /opt/script-directory has +r +w and +x set for jenkins user.
Another workaround would be not to change the current directory, just execute sh with it:
sh '/opt/script-directory/run.sh'
I had a similar concern when trying to execute a script in a Jenkins pipeline using a Jenkinsfile.
I was trying to run a script restart_rb.sh with sudo.
To run it I specified the present working directory ($PWD):
sh 'sudo sh $PWD/restart_rb.sh'

Restarting build steps from the failure point on Hudson/jenkins

My requirement is , Say for example for a job on Jenkins/Hudson , i have configured three build steps which perform 3 separate tasks.
Step1: Execute shell script (echo $PATH)
Step2: Execute Shell Script (sgsh)
Step3: Execute shell Script (echo $JAVA_HOME)
IN these build steps say for example step 2 fails , I need a plugin which will allow me to restart the build from step2 since step1 is already completed successfully. Is there anything available?
Check Conditional BuildStep Plugin . With Run Condition Plugin it do what you want.

Resources