Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Trigger a Jenkins Build with UI from Jira Edited

Hello everybody,

I am trying to trigger a Jenkins build from Jira. I have a UI element (Trigger Jenkins Build button) in my Test Plan in Jira. I followed each step in the following link Script Runner. When I click the button, nothing happens but when I used the link 

https://${jenkinsHostPort}/job/${jobName}/buildWithParameters?token=${token}&TESTPLAN=$issueId" then I can see a new Jenkins build. I expected the same behavior when I click the button.

In groovy Script (trigger_jenkins_build_restapi_endpoint.groovy), I changed https to http, rest of the code is same. 

Advance thanks for your help.

3 answers

Any idea?

UPDATE: When I right click the Trigger Jenkins Build button and copy the link I saw the following Error

{"message":"https","stack-trace":" https\n\tat Script138$_run_closure1.doCall(Script138.groovy:43)\n\tat\n\tat\n","status-code":"INTERNAL_SERVER_ERROR"}

Hi Beril,

I want to trigger a job on Jenkins from post function on Jira. Did you can solution your problem?


@nihcet  Please check out my reply below. I think it could help you. 

Hey all, (my first ever community contribution here :p) 

I searched and searched for a solution for this and only ever found bits and pieces I could use. 

I ended up coming up with the following http Builder solution. The goal was to define some current issue parameters, and then take those parameters and pass them into the jenkins build. I'm now successfully triggering builds with parameters in jenkins by this http builder script using scriptrunner for JIRA.

Really hope this helps, I've thoroughly enjoyed this solution now that it's finished. 


Note ** if you do not have explicit networking connectivity in place from your jira instance to your jenkins instance you will be banging your head for wasted hours attempting to get a http post to hit jenkins. I didn't realize that both servers behind our firewall still needed some explicit routes defined at the networking level to allow these machines to communicate. If you're getting time outs / or host's "not resolving" errors it's either the DNS isn't able to resolve (devops / infra team can help) or it's a networking routing issue (devops /infra team can help)

Also Note** I've removed my jenkins auth key & login from, and the endpoints for privacy. 


(Pretty liberal imports, I don't even recall if I used them all) 

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.component.ComponentAccessor

IssueManager im = ComponentAccessor.getIssueManager()
MutableIssue issue = im.getIssueObject("SD-4672")

//get the value"Found Issue, retrieving custom fields..")

//Input 1
def im_first_name_cf_val = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_15201"))

//input 2
def im_last_name_cf_val = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_15202"))

//input 3
def im_username_cf_val = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_15203"))

//input 4
def im_email_cf_val = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_15204"))

//input 5
def preferred_client_name_cf_val = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14302"))

//input 6
def client_backend_institution_name_cf_val_list = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_13709"))
def client_backend_institution_name_cf_val = client_backend_institution_name_cf_val_list.find{true}.toString()

//input 7
def client_user_admin_cf_val = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14304"))

//selection 1
def infrastructure_location_cf_val = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_15205"))

//selection 2
def uploader_type_cf_val = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_15206"))

// Input 8
def zip_code_cf_val = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_15700"))

//Store your jenkin parameter here as a map
def data = [IM_FirstName: "$im_first_name_cf_val", IM_LastName: "$im_last_name_cf_val", User_Name: "$im_username_cf_val", IM_Email: "$im_email_cf_val", Institution_Label: "$preferred_client_name_cf_val", Institution_Name: "$client_backend_institution_name_cf_val", Client_Email: "$preferred_client_name_cf_val", Infrastructure_Location: "$infrastructure_location_cf_val", Uploader: "$uploader_type_cf_val", Zip_Code: "$zip_code_cf_val"]

def httpBuilder = new HTTPBuilder("http://<yourJenkinsEndpointHere>/job/<yourJobPath>/buildWithParameters")
//Set Username and password here as authentication

def username='yourJenkinsEmailHere'
//Go to jenkins profile, create auth token, said user you make token for needs access to the build
def password='11122712371237139929s9s9see78467acacdd8099cc4'

String userPassBase64 = "$username:$password".toString().bytes.encodeBase64()

httpBuilder.setHeaders(["Authorization": "Basic $userPassBase64"])
httpBuilder.request(Method.POST, ContentType.JSON) {
uri.query = data
response.success = {resp, json ->
log.warn "request succeed with status ${resp.status}"
//log.warn "request succeed with status ${resp.status}, response body was [${resp.entity.content.text}]"
response.failure = { resp, json ->
log.warn "request failed with status ${resp.status}"
//log.warn "request failed with status ${resp.status} response body was [${resp.entity.content.text}]"

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you