Force gulp task to completion via command line - jenkins

I have a gulp task that runs a couple other tasks. One of the tasks is to run karma. A couple of the tests are failing, which causes the gulp to fail. Is there a way to force a gulp task to completion via the command line, or a way to manipulate the return code?
I am writing a Jenkins job for another project that I don't own, so I am not responsible for the failing tests. That said, I don't have commit privs to the SVN repo that their code is stored on. Yes, it would be easiest to just change the gulpfile, but I'd rather not write a script in the Jenkins job to append a new task. Although, that might be the only option.

I do not know of a 'gulp-native' way to do this. A very similar scenario to what you laid out is discussed in this gulpjs/gulp issue - Continue gulp on error? #75.
The ultimate resolution was to use gulp-plumber

Related

Jenkins execute command only if previous one failed

I have the following problem. I have a command that unfortunately only works from time to time in powershell. Sometimes an error comes sometimes it runs through.
Now I am looking for an option in the declarative Jenkins pipeline to execute a step, if this step fails it should execute another command.
However, if the first command runs through, skip the second command, because it is then no longer necessary.
Unfortunately I don't know at all how to implement this.
I have thought about catch error.
I have thought about if else .
Maybe what you need it's already resolved here. I've been working with try/catch because I had same issues of unstable executions and works like a charm.
Try-catch block in Jenkins pipeline script

Gracefully stop a jenkins job

I use jenkins for my countinuous integration testing + possibility of starting manual checks.
My utilization is a job that :
Poll mercurial repo every 10 mn
Once a commit is done, start a generation (clone + make)
Launch a python suite test script
Gather result
Sometimes I want to be able to gracefully stop a job without using the "stop" button that simply aborts the test.
I managed to do it using a trick that check the presence of a file in the log directory used by the Python test suite
But I'm looking for a way to do it inside jenkins job itself.
Is there a way to have a customizable button for that purpose ?
I tried "batch task" plugin that would have been perfect BUT it waits for the python script to complete before execution ... So useless in my case (but the code works)
Thanks in advance for your help

How to run a single protractor testsuite in jenkins

I am trying to run my protractor tests in Jenkins and its working. The problem is, running the tests on a docker container and use multiple headless browsers doesnt work, because my test is using actions like hovering an element. My idea was to use multiple test suites:
local: not headless, for presentations
external: headless (test cases without actions like hovering an element), Jenkins
I added the suites in the protractor.conf.js file.
Typing
protractor protractor.conf.js --suite local using the terminal works fine and as expected, but in my Jenkinsfile.feature it says
npm run e2e..., which runs also the testsuite I dont want to be executed.
So my Jenkins tests fail, just because the wrong testsuite is executed.
Replacing npm run e2e... with
protractor protractor.conf.js --suite local in the Jenkinsfile.feature doesnt work neither. I hope there is a way to tell Jenkins what suite to run. Thank you
Even though your question sounds like 'how can one develop a website' I'll try to walk you through the steps. But your question it too broad especially given that you didn't provide your error stack and the content of package.json, config file, docker file and jenkins job you're running
You gotta break your task into multiple layers (and this relates to any parameter you want, headless or multiple suites) and resolve them one by one
Make sure your protractor can take this parameter, by passing from the CLI. For example
protractor protractor.conf.js --suite local
But don't forget to add default value if nothing is passed
Once 1 is tested and works, go to the next layer, which should be docker in your case. Open Dockerfile where you declare the image, and add environment variables that you will be passing to protractor. Define the command to run your script once a container is spun up from your image
When you have your docker image working as expected, find out how to pass variables to that image when spinning up a container. Normally it should be like following
docker run -e SUITE=“regression” protractor_image
When you have the image in Jenkins master or slave, and you can run tests from CLI, you can work on your job. Again, depends on what you're doing pipeline job or regular freelance job, your steps maybe different. But the logic remains the same. You need to add a job, and make it run tests by hardcoding parameters
When the job works, add input parameters and ensure that can be used
I'm sure you'll have questions about each item or the list, so I'd suggest to open a new question for each and provide more details for them. Good luck

How can I create a jenkins job, who must execute test on commit?

I'm beginning with Jenkins.
I want, that each time I do a git commit (or push?), that the jasmine test of my ionic project was executed and must work before the commit can be done.
In reality, it has 2 questions:
How execute jasmine test with Jenkins?
In this moment I execute the test with:
npm test
How can I do for executing this tests with a commit (or a push)?
Thanks
Best regards
You have two ways to achieve the task.
GIT Hook: From GIT after commit or push execute the Jasmine test
Jenkins Trigger with GIT Hook: From Jenkins check the repo and execute the Jasmine test
Hooks from GIT
Look for the hidden directory in your git repo, you'll find a directory called "hooks" and inside it many examples of hooks:
First list the content of your repo main directory:
ls -ltra
You should see something like:
m.ortiz.montealegre#CPX-XYR3G1DTHBU ~/-argentina/.git
$ vim hooks/
applypatch-msg.sample pre-applypatch.sample pre-push.sample update.sample
commit-msg.sample pre-commit.sample pre-rebase.sample
post-update.sample prepare-commit-msg.sample pre-receive.sample
You have a whole guide of how to setup hooks here.
In your case maybe update would do the thing:
update The update script is very similar to the pre-receive script,
except that it’s run once for each branch the pusher is trying to
update.
Triggers from Jenkins with GIT Hooks
In this one you'll setup your Jenkins project build trigger with "Poll SCM" but do not specify a schedule.
Then with a post-receive hook from GIT notify the Jenkins Job about the changes:
http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository>?token=<get token from git to build remotely>
I found that example here.
Run the Jasmine tests
I don't know which O.S you're using but I hope it's a beautiful Linux box.
You can achieve pretty much the same with Jenkins. You need to consider the user (your user) and its permissions and check if the user which runs the Jenkins instance is allowed to execute the same.
Just create a new Jenkins Project and add a shell execution step with the test just like you said:
npm test
There are many questions regarding your particular environment, but I think that this will be a good guide for you.
There was a ticket about adding this functionality.
Finally the ticket was closed
slackersoft commented on 2 Dec 2016
At this point, I think it makes more sense to leave the code to do the watching of your specs and production code to one of the many external libraries that are built specifically for that.
The relate external library can be:
jasmine-node
nodemon
mochajs
gaze

Jenkins - Make pass/fail dependent on results from script command

I'm admittedly very new to using Jenkins, so I apologize if this is something simple I'm overlooking. In my Jenkins job, I have a bash command to run a Python script. Everything runs correctly at the moment, and the Python script works. However, the script can give a pass or fail result after running (to clarify, a fail doesn't mean the script crashed, just that it ran through and, with the variables given, gave the result that with those variables it is wrong). I need to make it so the job fails when the "fail" result is given, but I can't figure out a way to make the Jenkins pass/fail dependent on anything other than whether everything runs properly. How can I set it in such a way that whether the job passes or fails depends on the python script output? Thanks in advance for your help!
So from what I could figure out, the easiest way to do this is to modify the Python script so that it exits with a non-zero value when it returns the undesirable value, and with zero otherwise, so the success of the job will mimic the success of the script.

Resources