Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Execute script runner script from cmd line

xion_admin July 24, 2017

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 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 24, 2017

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.

xion_admin July 25, 2017

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?

xion_admin July 25, 2017

@Nic Brough -Adaptavist-

Do you have an idea?

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 26, 2017

Sorry, missed the email earlier.

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

xion_admin July 27, 2017

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

 

 

xion_admin July 28, 2017

@Nic Brough -Adaptavist-

Can you not help?

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 28, 2017

The paste doesn't work, sorry.

xion_admin August 1, 2017
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 1, 2017

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

xion_admin August 2, 2017

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
xion_admin August 3, 2017

@Nic Brough -Adaptavist-

Please help me, I cannot fix it without your help

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events