How to stop a build in Jenkins via the REST api ? - api

I have a job in Jenkins. A website of our own triggers builds of this job via the REST api. Sometimes we want to abort the build. Sometimes, it can be before the build is even started. In such cases we have the queueItem # instead of the build #.
How to do so via the REST api ?

If the build has started, by POST on:
http://<Jenkins_URL>/job/<Job_Name>/<Build_Number>/stop
Will stop/cancel the current build.
If the build has not started, you have the queueItem, then POST on:
http://<Jenkins_URL>/queue/cancelItem?id=<queueItem>
This is assuming your Jenkins Server has not been secured, otherwise you need to add BASIC authentication for a user with Cancel privileges.

Actually this question is already answered. So I will add, how to find id=<queueItem> , which I got stuck on finding this solution, which will helpful for others.
So, you can get <queueItem>, by - http://jenkins:8081/queue/api/json
Sample Output will be of json type like this one -
[{"_class":"hudson.model.Cause$RemoteCause","shortDescription":"Started by remote host 172.18.0.2","addr":"172.18.0.2","note":null}]}],"blocked":false,"buildable":false,"id":117,"inQueueSince":16767552,"params":"\nakey\t=AKIQ\nskey=1bP0RuNkr19vGze/bcb4ijDqVr8o\nnameofr=us\noutputtype=json\noid=284102\nadminname=admin","stuck":false,"task"
You have to take "id":117, and parse it to -
queueItem =117.
http://<Jenkins_URL>/queue/cancelItem?id=queueItem

Maybe you want to remotely send a post http request to stop a running build, there is a clue FYI, the jenkins job can stop another job(running build), like any jenkins admin click the X button when job is running.
Http Request Plugins is required by Jenkins ver2.17
Uncheck the Prevent Cross Site Request Forgery exploits option. Manager Jenkins -> Configure Global Security -> Uncheck
Setup Http Request Plugins's authorization. Manager Jenkins -> Configure System -> HTTP Request Basic/Digest Authentication -> add. Make sure the user has the job cancel permission
Job A is running. In job B, add build step as HTTP Request, URL: http://Jenkins_URL/job/Job_A_Name/lastBuild/stop, HTTP mode: POST, Authorization select the user you have just set, then build job B.
Done

If you only need to cancel the active build from a certain job you can use this batch script (windows .bat syntax):
REM #Echo off
CLS
REM CANCEL ACTIVE BUILD
REM PARAMETER 1 ACTIVE JOB NAME
if [%1] == [] GOTO NO_ARGUMENT
SET domain=https://my.jenkins.com/job/
SET path=/lastBuild/stop
SET url=%domain%%1%path%
"\Program Files\Git\mingw64\bin\curl.exe" -X POST %url% --user user:pass"
GOTO THEEND
:NO_ARGUMENT
Echo You need to pass the active jobname to cancel last build execution
:THEEND
Path to your local curl needs to set.

Related

How to return custom exit code status in puppet apply using biemond orawls module

I am using puppet module "Biemond orawls" orawls to install and orchestrate weblogic server, in orawls for successful configuration change puppet returns
exit code and i restart the weblogic server for every successful "Change" to update the changed configuration which is not good every time, because during changing anything in weblogic from weblogic admin console we get the indication that server restart required which is only applicable for particular selected attribute or resource changes, and orawls do not give any option to get status of restart required like WLST, so i want to use WLST command isRestartRequired([attributeName]) during every edit session inside orawls code which will tell me if restart is required or not instead of restarting server for every successful change in weblogic server and i want this status to be returned from orawls to puppet apply command.
i am using puppet apply command to change any weblogic server resources like -
apply -e 'include amd_wls_cluster' ${PUPPET_COMMON_OPTS} ${IS_NOOP}
which returns few specific code like - Puppet apply exit code
--detailed-exitcodes: Provide extra information about the run via exit codes. If enabled, 'puppet apply' will use the following exit codes:
0: The run succeeded with no changes or failures; the system was already in the desired state.
1: The run failed.
2: The run succeeded, and some resources were changed.
4: The run succeeded, and some resources failed.
6: The run succeeded, and included both changes and failures.
Here i want to add my own custom status code may be 7 if WLST isRestartRequired([attributeName]) return true
i tried searching a lot but could not find anything, is this possible to return custom exit code from biemond orawls to puppet.
or is there any such option which i can use to identify if server restart is required using puppet's biemond orawls module.
Thank you in advance.
i tried searching a lot but could not find anything, is this possible
to return custom exit code from biemond orawls to puppet.
No, Puppet does not provide a mechanism for customizing its exit codes. There is no hook exposed to modules that could provide for this.
or is there any such option which i can use to identify if server
restart is required using puppet's biemond orawls module.
As I wrote in comments, the usual pattern is to let Puppet manage the service restart (or even a server restart, though I don't see why that would be necessary). It's unclear exactly how that would look with orawls, which appears to have a ridiculously large public interface, but it looks like the docs contain several example configurations, and I would hope to see such a thing in at least one of those.
Alternatively, the Puppet agent can be configured (and in some versions is configured by default) to send reports describing each run to (typically) the master. The master can then be configured to process these via a user-provided processing module. These reports contain information about exactly which resources were changed, so you could surely use them to decide remotely whether to restart services / servers.

Ansible : get playbook result

I am using Ansible to deploy a PHP website into my servers (production, staging, etc), and I would like to get a notification (via skype).
For it I need learn ansible to send post request (with some params) when any ansible task starts or finishes (with result : success/failed or with error description)
Help me please with realization of all this stuff since I have any ideas about it. =(
You have to write your own callback plugin.
Take a look at slack notification plugin.

intellij : control jenkins plugin crumb data

i've installed jenkins server and run it.
i've installed kenjins control plugin on intellij as described in this lin https://github.com/dboissier/jenkins-control-plugin
try to configure jenkins settings --> test connection gives me [Missing or bad crumb data]
i am using intellij 2016.3 and jenkins server 2.19.4
thanks a lot.
This solution worked for me. Here are the steps:
Generate an API token by going your Jenkins home page > your name in the top right corner click > Configure > "Add new token". Copy this token.
In Intellij Settings > Tools > Jenkins Plugin, fill in server address and username. For password, put in the token copied in step 1 and leave the "crumb data" section empty.
Test connection should succeed now.
CRSF handling has improved these days - you likely don't actually need crumb data, and the error is a misnomer. You may actually need to go to <jenkins-server>/user/<your-user-name>/configure and add an API token. This token is then used as your password in the IDE configuration. See this comment
You may need to get the crumb with the following URL on the browser
http://<jenkins_url>/crumbIssuer/api/json?tree=crumb
And put the crumb value in the Jenkins plugin settings.
You can look at here.
Ran into the same problem. Found the answer (by azharsikander) here: https://github.com/dboissier/jenkins-control-plugin/issues/134.
It's because the current implementation sets .crumb header but Jenkins 2.0 is using Jenkins-Crumb header.
https://github.com/dboissier/jenkins-control-plugin/blob/91ef83f318a7ebe6c50b9395342b24b0f51d542f/src/main/java/org/codinjutsu/tools/jenkins/security/DefaultSecurityClient.java#L45

Zed Attack Proxy Authentication error(401) - daemon mode

I have a local website hosted on IIS and I am trying to scan my application with ZAP tool executed in daemon mode. Everything works fine until I disable the "Anonymous Authentication" method from IIS and the only method enabled is "Basic Authentication". The error I get is "Failed to attack the URL: received a 401 response code".
Is there any possibility to send the login credentials from daemon mode?
The command looks like this: zap.bat -quickurl "urlToTest" -quickprogress -daemon -cmd.
The -cmd option puts ZAP into commandline / inline mode.
Use the -daemon mode to put ZAP into daemon mode, at which point you'll need to use the ZAP API to interact with it.
To handle authentication you will have to add your application to a Context and then specify the authentication.
We have a FAQ for Form Based authentication: https://github.com/zaproxy/zaproxy/wiki/FAQformauth You'll need to do something similar but specify 'HTTP/NTLM Authentication' : https://github.com/zaproxy/zap-core-help/wiki/HelpStartConceptsAuthentication
I'd recommend testing this using the ZAP UI first - you can also then export to Context to reuse in daemon mode.
Any problems then its probably best to head over to the ZAP User Group: http://groups.google.com/group/zaproxy-users
Simon (ZAP Project Lead)

Siteminder issue Unable to process SMSESSION cookie

The very first time I'm able to logging in into a web page and after that if I click any link its redirecting to login page.
I see the message in the logs as "Unable to process SMSESSION cookie" and there is no error other than this.
All technologies that I used are tagged for the question.
Could any one help me.
Here is the logic to fix the problem until to get the proper siteminder package:
Due to the siteminder package update, we got into this issue.
The siteminder setup needs to be changed after a MVN build. Hence MVN build will create a conf files every time.
Also every time you do a maven build, the settings go back to the ‘wrong’ one.
So after every maven build, the following steps must be followed:
Brief Steps:
1. In the web server- remove the redirect at the end
2. In the app server - remove the UAA,
3. In the app server - remove the context-param (devSecurityContext.xml part)
4. stop and start both web and app server's .
Detailed Steps:
Go to the config directory of the web instance and remove the line:
Redirect 307 /login.fcc
From this file config/redirects.conf
Go to the web.xml file and remove the UAA filter – i.e. the following lines:
Remove all the filter configurations.
`
In the same file above the UAA modify the context-param – remove the devSecurityContext :
Modify the line:
/WEB-INF/spring-af.xml,/config/spring/context-.xml,classpath:/config/spring/context-.xml,/WEB-INF/devSecurityContext.xml
To
/WEB-INF/spring-af.xml,/config/spring/context-.xml,classpath:/config/spring/context-.xml