~ / archivo / stackoverflow / 44655792
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
- Smashing 2017-06-23 09:00 Hi. I have never used ionic, but on jenkins how do you execute tasks? So for our android builds (also on jenkins) we have a gradle plugin and you can execute tasks such as "build". If you have options such as that won't it be possible to add "npm test" to the tasks and it should just work?.
- Marcelo Idemax 2017-06-23 09:12 did I get it right? you want to run a test before a commit be done?
-
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 -ltraYou 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.sampleYou 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 testThere 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: