Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,360,265
Community Members
 
Community Events
168
Community Groups

Script Runner not working when trying to trigger pipeline from jira through post functions

Edited

Hi All,

We have been trying to trigger pipeline in Jenkins from jira through post functions. As the script not executing while making a below grooving script through script runner plugin in the jira workflow

Use case :

In workflow While making transition from pipeline creation approval to pipeline creation

Code used :

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def repoName = customFieldManager.getCustomFieldObjectByName("Git repositories")
def pipelinename = customFieldManager.getCustomFieldObjectByName("CI BuildJob")
def techstackname = customFieldManager.getCustomFieldObjectByName("Tech Stack")
def repoNameValue = issue.getCustomFieldValue(repoName)?.value
def piplelineNamevalue = issue.getCustomFieldValue(pipelinename)?.value
def techstackNameValue = issue.getCustomFieldValue(techstackname)?.value
def BUILD_TOKEN = "11268982e8e7f9d983d79b37bbeb5e4d1d"
def urlConnection = new URL("http://3.14.131.151:8080/job/DSL_Demo_Seed/buildWithParameters?token=${BUILD_TOKEN}&GitRepoName=${repoNameValue}&techstack=${techstackNameValue}&name_job_create=${piplelineNamevalue}").openConnection()
def authString = "admin:11268982e8e7f9d983d79b37bbeb5e4d1d".getBytes().encodeBase64().toString()
urlConnection.setDoOutput(true)

urlConnection.setRequestMethod("POST")

urlConnection.setRequestProperty("Authorization", "Basic ${authString}")

urlConnection.setRequestProperty("Content-Type", "application/json")

//urlConnection.getOutputStream().write(message.getBytes("UTF-8"))

def postRC = urlConnection.getResponseCode();

println(urlConnection.getInputStream().getText())

 

Expected output :

Pipeline must be created at jenkins end with the above code 

 

Please note :We used the script on creating repo in github in validation part of the workflow through script runner it worked

Has anyone come across with the same scenario who could assist with this ?

 

 

Regards

Arthi Balraj

0 comments

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Jira Software

An update on Jira Software customer feedback – June 2022

Hello Atlassian Community! Feedback from customers like you has helped us shape and improve Jira Software. As Head of Product, Jira Software, I wanted to take this opportunity to share an update on...

5,020 views 18 32
Read article

Atlassian Community Events