Break build on Travis if pylint doesn't have an specific rate - travis-ci

I currently have a project that I'm using pylint and pytest. I use Travis to validate my build, and also run pylint to verify the code quality.
But I wanted to do something different and not finding anywhere about how I should proceed. I want my Travis build to break if the code rating is below 9.5, not even running the pytest script. Therefore I can guarantee that all the guidelines are being followed.
What can I do to trigger this? Do I have to configure my .travis.yml or pylintrc?

I see two ways to go about this:
write your own reporter for pylint that exits with something non-zero when the report score is below the threshold. custom reporter
hook into/extend the pytest-pylint plugin. Which already has programmatic access to the linter run. pylint-pytest code (runs before the actual pytest tests)

Related

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 to deploy Drupal with Jenkins only if the tests are successful

I have some doubts about the correct configuration of Jenkins to ensure the continuous integration of a Drupal project but I arrive at some contradictions.
Let me explain: the deployment, after all, consists in executing:
cd / path / to / web / root
pull from git
drush config:import
drush cache:rebuild
The tests are launched with the command
../vendor/bin/phpunit --verbose --log-junit ../tests_output/phpunit.xml -c ../phpunit.xml
The contradiction is that I do not understand when to run the tests.
Before the pull does not make sense because the last changes are missing, after the pull if any test goes wrong I should be able to restore the situation before the pull (but I'm not sure it's a safe action).
I'm trying to run the tests directly in the workspace of jenkins and to do this I also created a separate database, but at the moment I get the error:
Drupal\Tests\field_example\Functional\TextWidgetTest::testSingleValueField
Behat\Mink\Exception\ElementNotFoundException: Button with id|name|label|value "Log in" not found
What could be the best strategy to follow?
So, your order seems ok - pull first then run tests.
However, you can have 2 Jenkins jobs. First runs, your tasks. 2nd runs ONLY if your first job completes without failure.
There are ways to get exit status from scripts - see following plugins/notes about that.
How to mark Jenkins builds as SUCCESS only on specific error exit values (other than 0)?
How to mark a build unstable in Jenkins when running shell scripts

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

How can I force update code coverage trend graphs on failed jobs

How can I publish the results of the code coverage to the trend graph even if the job fails after the jacoco analysis?
For Findbugs, PMD, etc. this can be achieved with the canRunOnFailed setting. Is there something similar for JaCoCo?
On project level I see the trend graph which only considers the successful builds. I would also like to see the coverage graph updated if the job fails.
This is tracked by JENKINS-28479:
ProjectActions (and trend graphs) do not appear for failed projects
This problem is not only related to the JUnit plug-in. In general, every plug-in that has been migrated its actions to a SimpleBuildStep has this problem. The affected source code is in SimpleBuildStep.
A test case that exposes this bug is WarningsPluginTest#should_not_skip_failed_builds_with_option_run_always
This is still open.
Original answer:
This is not specific to the maven jacoco build step: all you need to do is make sure that build step always return "success".
If you are using pipelines, you can wrap your step in a try/catch.
If you are using a regular job definition, you could consider a shell/windows command step where you return 0 (or exit /b 0) after the mvn command.
The next build step would be the mvn sonar:sonar publication one, which will then always be executed.

YSlow Phantomjs and Jenkins jobs failing, but analysis successful

I'm going through the tutorial on YSlow and Phantom js in Jenkins here: http://yslow.org/phantomjs/
Everything appears to be working great except the Jenkins builds are failing. I think this is due to the violations that YSlow is finding (6 for the particular site I am measuring). I'd rather have the build be successful (or unstable) vs. failed though
Is that possible with this or will I have to resort to something like the postgroovy or text finder plugin?
This is the console output:
phantomjs.exe yslow.js -i grade -t 50 --format junit http://www.somesite.com 1>yslow.xml
D:\Apps\Jenkins\workspace\YSlow_Test>exit 6
Build step 'Execute Windows batch command' marked build as failure
Thanks
Any non-zero exit code at the end of your Execute Windows batch command build step will result in build step being marked as failure.
To have the build step marked as success, you need an exit code of 0. I don't know anything about "yslow" or "phantomjs" and why they are giving you exit code of non-zero, but from "batch" side of things, you need only write exit 0 at the end of your build step if you want to overwrite the exit code of your phantomjs command.
You can then use Text Finder plugin to parse the console log and mark build as unstable when certain conditions are met.
Reading over this answer, Configuring yslow on Jenkins looks like you need TAP plugin to have the functionality of unit testing marking the build as unstable automatically

Resources