I'm trying to do a pretty simple thing I believe - trigger a Jenkins job from a slash command in slack. I want to type /dump in slack and that should trigger particular jenkins job. I'm using Slack Slash command to achieve this and the setup is very simple - type command, type URL, select POST/GET method.
I tried two methods - first was to use Build Authorization Token Root Plugin following this tutorial - in this case I configured Slack slash command to make GET request on the URL: http://jenkins_url:8080/job/db-dump-setup/build?token=MY_TOKEN - If I put the URL to my browser, the job gets triggered, if I run the /dump command, slack responds with:
slackbot [3:41 PM]
Darn - that slash command didn't work (error message: `403_client_error`). Manage the command at text.
The second approach I tried was following this tutorial. In this case I created new user in Jenkins and got API token. When running this command from my terminal: curl -X POST http://USER:TOKEN#slack_url:8080/job/db-dump-setup/build, the job gets again triggered, however when configuring the Slack slash command with the same URL and making POST request, I get the same error: 403_client_error
I tried to google this specific error but didn't find anything useful, also there are no more details for the error or any logs which could help me to troubleshoot this further.
Anyone run into something similar and knows how could I get this resolved?
I was able to resolve this so answering my own question in a case someone else runs into this. In order to make the first case work (Using the GET request), I had to enable the "Allow anonymous read access" in Jenkins, in Manage Jenkins -> Configure Global Security as per the screenshot below.
You should not need to enable anonymous access.Your jenkins requires authentication. Update your url like http://user:auth-token#jenkins-host:port.Auth token can be generated at the following URL JENKINS_HOST/me/configure
Related
I've been struggling with a webhook configuration for quite some time now and would to reach to you all for some help.
I have configured a webhook in my bitbucket repo to push to jenkins so that jenkins can receive the notification and begin a build of the project.
At first we had some networking issues, which have been corrected. i then started to get a 403 error (crumb issue). After some research i was able to add my login and API token to the webhook url and now getting a 404 error. The url cannot be found.
my webhook url looks something like this.
https://username:apitokenhere#serverwherejenkinsis.com:8080/projectname/bitbucket-hook/
404 error
But when i use the webhook URL
https://username:apitokenhere#serverwherejenkinsis.com:8080/bitbucket-hook/
I get a 200 message
Is there a config file that i need to change within jenkins to "listen" to that URL? my project is build properly with the option of "bitbucket webhook trigger" selected. I have also selected "Poll SCM" where i found some sites suggesting this option. But when i push a commit on my repo, i dont get any feedback from jenkins.
Any help is greatly appreciated.
I wanted to post an update as i have figured out what my problem was.
the webhook url did not need my credentials to end the bread crumb error. in fact the hook url is pretty basic.
https://serverwherejenkinsis.com:8080/bitbucket-hook/
I did not need to have the project name in the URL. ALSO, the project name in jenkins needed to match exactly what the project name is within bitbucket.
Does anyone know a command or steps to abort a Jenkins Freestyle job?
I can use a timeout after 3 minutes but I don't see anyway to instantly exit like Pipeline jobs can by setting currentBuild.result = 'ABORTED'.
I'm running Jenkins on Windows so looking for a bat command or similar solution.
You can add "kill" to the end of the path of any running job's execution,
Ex: https://hostname/jenkins/job/DDNS/4902/kill
and it will take you to a page that says:
This URL requires POST
The URL you're trying to access requires that requests be sent using POST (like a form submission). The button below allows you to retry accessing this URL using POST. URL being accessed:
https://hostname/jenkins/job/DDNS/4902/kill
If you were sent here from an untrusted source, please proceed with caution.
There will be a button for "Retry Using POST" -- click that and it will automatically kill any running job, aborting at current stage.
Therefore, if you want to make a script, use that URL with some logic to land on the right job number, with a POST method, and it should do what you want.
I'm trying to trigger build in Jenkins remotely using URL.
the URL is : "http://myJenkinsURL/job/myProjectName/build?token=SOME_TOKEN&EXTID=lkjsdfljsdflkjsdfjklsdflkj"
The problem is when i try to trigger this build it redirect me to my Jenkins and ask me to insert the parameter but i already passed it over the URL.
Is there something that I'm missing in the process?
https://wiki.jenkins.io/display/JENKINS/Parameterized+Build has the gory, but it mentions that you want a URL like this (note buildWithParameters):
http://server/job/myjob/buildWithParameters?token=TOKEN&PARAMETER=Value
so your call might look like this:
curl -X POST "http://myJenkinsURL/job/myProjectName/buildWithParameters?token=SOME_TOKEN&EXTID=lkjsdfljsdflkjsdfjklsdflkj"
so we're trying to use the Jenkins API to invoke a build with a file parameter. Basically we're trying to give it the files to build in ZIP format. We have a ZIP plugin installed to unzip the build file, but we can't get that far.
Basically we're trying to use the buildWithParameters endpoint, but based on scouring info available online combined with a test I have set up in Postman, it would seem that buildWithParameters only works with parameters that exist on the query string.
If we use the build endpoint, we're able to submit the file successfully, both in a node app we built (using the request library) and in Postman. But if we roll back to buildWithParameters, using the same exact configuration, the file is not processed successfully by Jenkins (we get a file not found error).
Am I right about buildWithParameters only working with query string parameters?
To preempt why not just use the build endpoint: we need the build number back, which we get back from buildWithParameters but don't seem to get back with build.
To reiterate my question: is it possible to use the buildWithParameters endpoint and upload a file parameter? It would seem like it is, but we have not been able to get it to work.
I know how to provide build parameters:
wget --post-data='json={"parameter": {"name": "testparam", "value": "HELLO"}}' http://jenkins/job/Job1/build?delay=0sec
But, is it possible to provide a shortDescription and userName in a Jenkins remote API build request via wget/curl?
How should it look like in json or xml? Is there any manual/guidance on the net?
I will use this in along with the problem described in Trigger dynamic set of jobs. I want to provide triggered job with the calling job name and build number.
You may consider using Jenkins CLI (http://[jenkins-host]/cli for help in the browser). You can specify a user to a build CLI command. I'm not sure what you mean by short description when starting a build, though.
Update: Please see Jenkins Wiki Authenticating Scripted Clients. I've created a user foobar ('full name' Foo Bar) and tried the following:
wget --auth-no-challenge --http-user=foobar --http-password=[apiToken] http://jenkins.yourcompany.com/job/your_job/build
Where the token is obtained from user configuration page: http://localhost:8081/user/foobar/configure. It worked. The user has to exist, though. Also, you must specify --auth-no-challenge option, otherwise it kicks off the build as anonymous. The status description says Started by user Foo Bar.
Another Update If everything else fails, you may consider the following workaround: start all builds via the Parameterized Trigger Plugin with an additional boolean parameter that tells the triggered job whether to run or not. In case the job is asked not to run it would fail immediately and call a 'clean-up' job passing to it the build info; the clean-up job then will delete the build from the system.