Execute script runner script from cmd line

We have a script which retrieves us the version history:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import java.text.SimpleDateFormat 
import java.util.Date

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def userManager = ComponentAccessor.getUserManager();

// Adjust HERE the buildnumber to a certain version, where you want to retrieve all closed devs
def buildNumber = 7

def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
def query = jqlQueryParser.parseQuery('project = DIV AND issuetype = Development AND status = Closed AND fixVersion = 2.8 AND "Build Number" ~ ' + buildNumber.toString())
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
def closedDevs = "";
def closedDevList = [];
def featureList = [];
def bugList = [];
results.getIssues().each {issue ->
    Issue parentIssue = issue.parentObject;
    def issueName = parentIssue.getIssueType().name.toUpperCase();
    def issueSummary = issue.getSummary();
    if (issueSummary.substring(0, 8) == "[DEV] - ")
    	issueSummary = issueSummary.substring(8, issueSummary.length());
    
    closedDevs += "* {{$issueName}} " + issueSummary + " {{JIRA|$issue.key}}<br>";
    
    def text = "* {{$issueName}} " + issueSummary + " {{JIRA|$issue.key}}";
    if (issueName == "FEATURE")
    	featureList << text;
    else
        bugList << text;
}

def metadata = "=== Version 2.8.0 - Build $buildNumber ===<br>";
    metadata += "<br>";
    metadata += "Release: " + new Date().format('YYYY-MM-dd') + "<br><br>";

featureList.each {
    metadata += "${it}<br>";
}

bugList.each { 
    metadata += "${it}<br>";
}

return metadata;

 What we want to do now is, executing this script from the cmd line (windows batch) and retrieve the data. It must not be directly cmd line, but I need somehow the returned data in a text file.

 

1 answer

0 vote

Convert it into a "REST Endpoint" (mostly copy and paste I think), then you can poke JIRA any time you need it to pull back the output.

I was able to setup an endpoint.

However, I need an additional argument to setup the build number

e.g:

http://jira/rest/scriptrunner/latest/custom/retrieveReleaseNotes/49

I need to read out the number 49 and want to use it in my script.

How can I do this?

Sorry, missed the email earlier.

Yes, have a look through https://scriptrunner.adaptavist.com/latest/bitbucket/rest-endpoints.html

My reply was not accepted because of an inappropriate language or spam....

Thats why I have to paste the reply here:

https://paste.ee/p/m5oNU#ZueE5Ghy3m1WycxuIck5Lir09QzuuTwW

 

 

The paste doesn't work, sorry.

Probably, but I don't know what it's got to do with the question.

What do you mean what its got to do with the quqestion?

I cannot parse the argument:

I get following error:

message    "Cannot cast object 'com.atlassian.plugin.servlet.PluginHttpRequestWrapper@631bb09c' with class 'com.sun.proxy.$Proxy2885' to class 'groovy.lang.Closure'"
stack-trace    "org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.atlassian.plugin.servlet.PluginHttpRequestWrapper@631bb09c' with class 'com.sun.proxy.$Proxy2885' to class 'groovy.lang.Closure'\n\tat com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate.methodMissing(CustomEndpointDelegate.groovy:20)\n\tat Script559$_run_closure1.doCall(Script559.groovy:30)\n\tat com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.doEndpoint(UserCustomScriptEndpoint.groovy:308)\n\tat com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.getUserEndpoint(UserCustomScriptEndpoint.groovy:193)\n"
status-code    "INTERNAL_SERVER_ERROR"

 

The error seems to be because of
 
def extraPath2 = getAdditionalPath(request)
 
You find everything inside the paste

@Nic Brough [Adaptavist]

Please help me, I cannot fix it without your help

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

29,476 views 26 12
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you