Forums

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

jira 7.6.0 scriptrunner 5.3.1 after updating typehandling exception

Krasina Anna February 5, 2018

Hello! After updating scriptrunner to version 5.3.1 i'm running a script and getting the error: 

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.onresolve.scriptrunner.canned.jira.utils.ConditionCustomScriptDelegate@18538353' with class 'com.onresolve.scriptrunner.canned.jira.utils.ConditionCustomScriptDelegate' to class 'com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate'

I included imports:

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.issue.Issue
import javax.ws.rs.core.Response
import javax.ws.rs.core.Response.Status
import groovy.json.JsonBuilder
import com.atlassian.jira.project.Project
import com.atlassian.jira.user.ApplicationUser
import java.text.SimpleDateFormat
import java.sql.Timestamp;
import java.text.DateFormat
import com.onresolve.scriptrunner.canned.jira.admin.CopyProject
import com.atlassian.jira.issue.IssueManager
import groovy.json.JsonSlurper;
import groovy.json.StreamingJsonBuilder;
import groovy.json.JsonBuilder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption

@BaseScript CustomEndpointDelegate delegate

Previously, the script was executed without errors

In the body of the script contains a call to the built-in script copyProject. Can this cause an error?   Any help will be greatly appreciated.

def copyProject = new CopyProject()
def inputs = [
(CopyProject.FIELD_SOURCE_PROJECT) : template,
(CopyProject.FIELD_TARGET_PROJECT) : key,
(CopyProject.FIELD_TARGET_PROJECT_NAME) : name,
(CopyProject.FIELD_COPY_VERSIONS) : true,
(CopyProject.FIELD_COPY_COMPONENTS) : true,
(CopyProject.FIELD_COPY_ISSUES) : true,
//(CopyProject.FIELD_COPY_GREENHOPPER) : false,
(CopyProject.FIELD_COPY_DASH_AND_FILTERS) : false,
// (CopyProject.FIELD_ORDER_BY) : "Rank",
]
def errorCollection = copyProject.doValidate(inputs, false)
if(errorCollection.hasAnyErrors()) {
return Response.status(Status.BAD_REQUEST).entity(new JsonBuilder([Res: errorCollection.toString()]).toString()).build()
}
else {
GroupManager GM = ComponentAccessor.getGroupManager()
def adminsGroup = GM.getGroup("jira-local-administrators")
assert adminsGroup // must have jira-administrators group defined
Collection<ApplicationUser> admins = GM.getUsersInGroup(adminsGroup)
assert admins // must have at least one admin
ComponentAccessor.getProjectManager().refresh()
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(admins.first())
copyProject.doScript(inputs)

 

 

 

3 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Petr Magnusek March 9, 2018

Yes, i konw about this ticket, but it is almost one month old and nothing happened. We have instance with 10000 users and our scripts are broken, so it is pretty serious problem for us and we need at least some "dirty" workaround.

Thanos Batagiannis [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.
March 9, 2018

Hey @Petr Magnusek 

I understand your frustration. A custom script would be a workaround, and I could help with that - depending on how complex you want to be. 

So what is your requirements ? Do you want to clone issues as well - when you copy the project ?

Petr Magnusek March 9, 2018

Hi, i think that this issue appear only, if i execute clone issue built-in script. What i need is to create complete copy of the issue (with many custom fields a all comments). i know how to create issue manually in script runner, but i don't know,how to copy all custom fields. There are many and it is complicated to name them in script one by one. is there a way how to easily clone issue with all custom fields and comments without usage of the built-in clone issue script?

Thanos Batagiannis [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.
March 9, 2018

Yes you are right, the bug is with the cloning issue part, in that case you can use the IssueFactory#cloneIssueWithAllFields

where you can give as param a "prototype" issue, so the new issue that will get created will be a clone of the one you passed as a param. 

I do not think that this will clone the comments as well, but that will be easy via the CommentManager after you get the fresh issue. 

If you want to give it a try and let me know if you need further assistance, I would be glad to help. 

Petr Magnusek March 9, 2018

Thanks, bu i need to clone the issue to the other project/issue type. Do i really need to write own script to fix the error in the cloneIssue buit-in script?

It should be small problem - cast wrong value type to variable type or something like this. 

 

Do you have any time estimation for fix?  thanks

0 votes
Thanos Batagiannis [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.
March 9, 2018

Hi @Krasina Anna @Petr Magnusek

This is a known issue, please start watching SRJIRA-2678 for updates. 

Apologies for any inconvenience.

Thanos

Edward Greathouse June 4, 2019

Hi Thanos,

This is what I have:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.ProjectManager
import com.onresolve.scriptrunner.canned.jira.admin.CopyProject
import org.apache.log4j.Level
import org.apache.log4j.Logger

def myLog = Logger.getLogger("com.onresolve.jira.groovy")
myLog.setLevel(Level.DEBUG)
myLog.debug("%%%%%%%%%%%GOODBYE%%%%%%%%%%%")

def issueProject = issue.getProjectObject()
def projectName = issueProject.getName()
def positionOfDash = projectName.indexOf("-")
myLog.debug("Project Name: '${projectName}'")
def companyName = removeTrailingSpace(projectName.substring(0, positionOfDash))
myLog.debug("Company Name: '${companyName}'")
def customerProjectObject = ComponentAccessor.getProjectManager().getProjectObjByName(companyName)
myLog.debug("Project object: '${customerProjectObject}'")

 


if (!customerProjectObject) {
myLog.debug("Customer support project not found, creating customer support project...")
def copyProject = new CopyProject()
def newProjectKey = companyName.substring(0, 6)
def newProjectDescription = issueProject.getDescription()
def newProjectLead = issueProject.getProjectLead()
def newProjectURL = issueProject.getUrl()
def newProjectAssigneeType = issueProject.getAssigneeType()
def newProjectTypeKey = issueProject.getProjectTypeKey()
def inputs = [
(CopyProject.FIELD_SOURCE_PROJECT) : "'${issueProject.getKey()}'",
(CopyProject.FIELD_TARGET_PROJECT) : "'${newProjectKey}'",
(CopyProject.FIELD_TARGET_PROJECT_NAME) : "'${companyName}''",
(CopyProject.FIELD_COPY_VERSIONS) : false,
(CopyProject.FIELD_COPY_COMPONENTS) : false,
(CopyProject.FIELD_COPY_ISSUES) : false,
(CopyProject.FIELD_COPY_DASH_AND_FILTERS) : false,
]

def errorCollection = copyProject.doValidate(inputs, false)
if(errorCollection.hasAnyErrors()) {
myLog.warn("Couldn't create project: $errorCollection")
}
else {
def util = ComponentAccessor.getUserUtil()
def adminsGroup = util.getGroupObject("jira-administrators")
assert adminsGroup // must have jira-administrators group defined
def admins = util.getAllUsersInGroups([adminsGroup])
assert admins // must have at least one admin

ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(util.getUserByName(admins.first().name))
copyProject.doScript(inputs)
}
}

However, I'm getting the error:
java.lang.IllegalArgumentException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token

Can you give me any ideas on what might be causing this?

Edward Greathouse June 4, 2019

Okay, I changed my script. This is what I have now:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.ProjectManager
import com.onresolve.scriptrunner.canned.jira.admin.CopyProject
import org.apache.log4j.Level
import org.apache.log4j.Logger

def myLog = Logger.getLogger("com.onresolve.jira.groovy")
myLog.setLevel(Level.DEBUG)
myLog.debug("%%%%%%%%%%%GOODBYE%%%%%%%%%%%")

def issueProject = issue.getProjectObject()
def projectName = issueProject.getName()
def positionOfDash = projectName.indexOf("-")
myLog.debug("Project Name: '${projectName}'")
def companyName = removeTrailingSpace(projectName.substring(0, positionOfDash))
myLog.debug("Company Name: '${companyName}'")
def customerProjectObject = ComponentAccessor.getProjectManager().getProjectObjByName(companyName)
myLog.debug("Project object: '${customerProjectObject}'")





if (!customerProjectObject) {
myLog.debug("Customer support project not found, creating customer support project...")
Thread executorThread = new Thread(new Runnable() {
void run() {
myLog.debug("Inside thread...")
def copyProject = new CopyProject()
def newProjectKey = companyName.substring(0, 6)
def newProjectDescription = issueProject.getDescription()
def newProjectLead = issueProject.getProjectLead()
def newProjectURL = issueProject.getUrl()
def newProjectAssigneeType = issueProject.getAssigneeType()
def newProjectTypeKey = issueProject.getProjectTypeKey()
def inputs = [
(CopyProject.FIELD_SOURCE_PROJECT) : "'${issueProject.getKey()}'",
(CopyProject.FIELD_TARGET_PROJECT) : "'${newProjectKey}'",
(CopyProject.FIELD_TARGET_PROJECT_NAME) : "'${companyName}''",
(CopyProject.FIELD_COPY_VERSIONS) : false,
(CopyProject.FIELD_COPY_COMPONENTS) : false,
(CopyProject.FIELD_COPY_ISSUES) : false,
(CopyProject.FIELD_COPY_DASH_AND_FILTERS) : false,
]
myLog.debug("Validating request...")
def errorCollection = copyProject.doValidate(inputs, false)
myLog.debug("I now know if it's valid...")
if(errorCollection.hasAnyErrors()) {
myLog.warn("Couldn't create project: $errorCollection")
}
else {
myLog.debug("It is valid!")
def util = ComponentAccessor.getUserUtil()
def adminsGroup = util.getGroupObject("jira-administrators")
myLog.debug("got group admins...")
assert adminsGroup // must have jira-administrators group defined
def admins = util.getAllUsersInGroups([adminsGroup])
myLog.debug("got users within the group...")
assert admins // must have at least one admin
myLog.debug("this is working still...")
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(util.getUserByName(admins.first().name))
copyProject.doScript(inputs)
myLog.debug("finished ")
}
}
})
executorThread.start()
}




def String removeTrailingSpace(String projectName) {
def lastSpaceCharacter = projectName.lastIndexOf(" ")
def lengthOfProjectName = projectName.length()
if (lastSpaceCharacter == lengthOfProjectName-1) {
return projectName.substring(0, lastSpaceCharacter)
} else {
return projectName
}
}
Edward Greathouse June 4, 2019

I'm not getting any errors, but the project is being copied and the logging stops after "validating request..."

Any ideas on what could be causing this?

0 votes
Petr Magnusek March 9, 2018

Hi, please, did you solve this problem? Thank You!

TAGS
AUG Leaders

Atlassian Community Events