Follow-up on "Trigger Jenkins build post-deploy"

#1

Howdy!

This is a follow-up based on my first issue from a while ago:
Trigger Jenkins build post-deploy

I’ve successfully set up the plugin Jenkins - Queue Job as the last step being triggered from our deployment to QA. However, an exception is thrown complaining about failed connection to the remote server. This might have something to do with the fact that our Octopus and Jenkins servers are on separate environments (IP space).

See the attached screen dump:

I’ve also tried running the code snippet directly from my machine via PowerShell, with a few modifications.
I ended up with an exception that included a 403 Forbidden status code.

PS H:\Documents> .\Octopus_Jenkins.ps1
Job URL: https://jenkins.intra.eika.no/job/felles-engine-selenium-regress/build
Building…
Job URL link: http://jenkins.intra.eika.no/queue/item/32220/
Exception in jenkins job: Den eksterne serveren returnerte feilen (403) Forbudt.

Should the Job URL link be using http or https? Could that be the reason for my failed attempts?
I’m using my own username and password to authenticate to the servers, not any provided global users, could that have some affect?

Any other ideas on what I could do to troubleshoot?

(Matthew Casperson) #3

Hi @anigma, thanks for reaching out.

The 403 response code you have received indicates that the credentials you have supplied to Jenkins are invalid, or that you have not included the correct crumb in the request.

A typical process in calling Jenkins is this.

  1. Perform a HTTP POST to http://yourjenkinsserver/jenkins/crumbIssuer/api/json. This will return something like this:
{
    "_class": "hudson.security.csrf.DefaultCrumbIssuer",
    "crumb": "574608b1e95315787b2fa0b74fce2441",
    "crumbRequestField": "Jenkins-Crumb"
}
  1. Perform a HTTP POST to http://yourjenkinsserver/jenkins/job/TheNameOfTheProject/build with the Jenkins-Crumb header set to the value of the crumb field in the JSON returned from step 1.

This will result in a Jenkins project being deployed.

When troubleshooting REST API calls to Jenkins it is useful to make the calls in a tool like Postman (https://www.getpostman.com/), because you can see the response text which will often indicate the underlying issue for a failed request. For example, in the screenshot below you can see a request that failed because of a missing crumb value.

Regards
Matt C

#4

Ahh, sweet. I’ll give that a try, much obliged!
I’ll report back if I happen to get stuck.

(system) closed #5

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.