protractor integration with jenkins - 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.

Related

I want to execute jenkins pipeline as a administrator

I want to execute jenkins pipeline as a administrator
or
I want to execute pipeline with specific cmd.exe.lnk that I setup 'run as administrator' option.
Also, When I tried to build below windows command, I can't watch the build log on console output.
[ windows command sample ]
- start (PATH)\cmd.exe.lnk /k "cd (PATH)\mvn clean package"
And,
I already tried to build with bat file that setup 'run as administrator' option.
but It was also just finished as 'success' but nothing to happen for me.
Please, let me know how should I do in this situation.

how to execute a bash script in a jenkins declarative pipeline

I have started recently using Jenkins in windows 10. I have a freestyle job that sync from the SCM, build a C++ solution and then it runs a batch script to upload to steam. I am trying to convert it to pipeline as I realized reading the documentation how much more powerful it is. My problem is that on the step to run the .bat file it gets stuck forever, this is the step:
...
Stage('batch script'){
steps{
bat 'start C:/Users/User/.jenkins/workspace/Project/Steam Build Scripts/scripts/build_dev.bat'
}
}
...
and this is the simple .bat file:
"C:\Users\User\.jenkins\workspace\Project\Steam Build Scripts\builder\steamcmd.exe" +login "someUser" "somePassword" +run_app_build "C:\Users\User\.jenkins\workspace\Project\Steam Build Scripts\scripts\app-build-813780-dev.vdf" +quit
running the same file from the freestyle job works fine like this:
I found out the way in case somebody has the same issue, due to the path containing spaces it has to be called like this:
bat ('call "C:/Users/User/.jenkins/workspace/Project/Steam Build Scripts/scripts/build_dev.bat"');

jenkins job for protractor cucumber

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

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