Scriptrunner VersionReleaseEvent not working as expected
I have a scriptrunner listener script that runs when a user selects a Version and choses the “Release” status change, on action: VersionReleaseEvent
My listener script will attempt to create a record on another internal release tool. If that call fails, I want to change the Version status BACK to Unreleased. My listener script works fine to unset the Version back to Unreleased on the Releases Tab, when an Administrator attempts to move a Version to the Release status, and fails. But the SAME code does NOT work when run on Manage Versions tab; and it leaves the Version in the Released status. Where in this case, I really want the status returned to Unreleased.
Can you examine your tool to find out why this scriptrunner command does not work on “Manage Versions” tab?
import com.atlassian.jira.component.ComponentAccessor
def vm = ComponentAccessor.versionManager
vm.releaseVersion(event.version, false)
DOCUMENTATION on .releaseVersion:
Thanks,
Darryl
Comments (25)
-
repo owner -
reporter Holger, I was mistaken. It appears that the .releaseVersion(event.version.false) code is equally intermittently working on BOTH “Releases” tab and “Manage Versions” tab.
Please close this issue, it is not valid.
I do not know why .releaseVersion() is intermittently working and not working on both tabs.
But Version Manager for Jira is not responsible.
-
reporter - changed status to invalid
vm.releaseVersion(event.version, false) is intermittently not working on both "Releases" and "Manage Versions" tabs. So it can't be Version Manager for Jira's fault. Closing ticket
-
repo owner - changed title to Scriptrunner VersionReleaseEvent not working as expected
-
assigned issue to
-
reporter Holger,
I’m still having this problem. However it is now ONLY showing up on my “Manage Versions” tab and not on the “Releases” tab. I don’t know what occurred to make it work every time now under the Releases tab, when it used to be intermittent there.
I still have not received an working answer from Atlassian Support on this issue. So I just added your email (holger@schimanski-web.de) to my open ticket with them so you can read the progress and their response. They are now saying the fault lies with Version Manager for Jira.. https://getsupport.atlassian.com/servicedesk/customer/portal/20/GHS-179283
Basically I run a scriptrunner script on the Release event, which runs a webapi command to our Release Tool named SCMS. If that fails, then I try to unrelease the Version. I was using the vm.releaseVersion(event.version, false) command to unrelease. But Atlassian said it was unreliable and make a call to the webapi command directly to unrelease.
In Curl, that command is the following:
curl -D- -u jirasysadm:mypassword -X PUT --data "{"id":"17800","released":false}" -H "Content-Type: application/json" https://jira.gvl.is.l-3com.com/rest/api/2/version/17800
In groovy, that becomes the following:
def jirawebapistatus = "Jira attempt: "
def authString = "Basic " + "jirasysadm:MYPASSWORD".getBytes().encodeBase64().toString()
def jiraurl = "https://jira.gvl.is.l-3com.com/rest/api/2/version/" + currentVersionId
def http = new HTTPBuilder(jiraurl)
http.request(PUT) {
headers."Authorization" = authString
requestContentType = ContentType.JSON
body = [id: currentVersionId, released: "false"]
response.success = { resp ->
jirawebapistatus = jirawebapistatus + "Jira Success"
return "Request was successfull with status ${resp.status}"
}
response.failure = { resp, htmlText ->
jirawebapistatus = jirawebapistatus + "Jira failure " + htmlText.Message
return "Request failed with status ${resp.status}"
}
}
log.info("Attempt to unrelease VersionName: " + currentVersion + "\n on Project " + currentProject + " status: " + jirawebapistatus)
It works when I do the releasing in the Releases tab, but does not work when I do the releasing in the Manage Versions tab.
Attached is a word document with my complete listener script output and the script itself.
What do you think about this?
I’m sorry for pulling you into this again, but I really do need a fix for this.
Thank you for your input.
Darryl Hahn
L3Harris
-
reporter word doc with Listener script contents and log output.
-
reporter - changed status to open
Atlassian Support says the issue is with Version Manager for Jira. On ticket https://getsupport.atlassian.com/servicedesk/customer/portal/20/GHS-179283
-
reporter Holger,
Atlassian Support just closed my ticket again:
https://getsupport.atlassian.com/servicedesk/customer/portal/20/GHS-179283
I have a simplified script that demonstrates that the unrelease command is not working on Manage Versions tab, but works in the Jira Releases tab. See file Simplified_Unrelease_failure_on_ManageVersionsTab.docx in my Atlassian Support ticket.
I’m unable to post a word document to this site. Only text and images are allowed to be posted here.
Regards,
Darryl
-
repo owner -
repo owner If I look at the two ways via Release tab or Manage Version tab, the log information is exactly the same. Both Release tab and Manage Version tab are triggering the same ScriptRunner code. The log shows that the VersionReleaseEvent is triggered also by Manage Version tab, which is expected behaviour.
If I understand your Simplified script correctly, on VersionReleaseEvent it set the version back to Unreleased, correct?
And if you set a version to Released via Release tab, the version is set back to Unreleased by the script. Any you see the respective version in both Manage Version tab and Release tab as Unreleased (after reload of the tab), correct?
And if you set a version to Released via Manage Version tab, then what is shown in Releases tab for this version and what in Manage Version tab (after reload of the page)? It is shown as Released or Unreleased? From the log I would expect it is shown as Unreleased, because the VersionReleaseEvent is also fired and ScriptRunner event would revert the version back to Unreleased, correct?
Please check reload of the Manage Version page, if the status is shown then as Unreleased?
-
reporter If I understand your Simplified script correctly, on VersionReleaseEvent it set the version back to Unreleased, correct?
Correct. Same code executed for both. It works for Releases tab, but not for Manage Versions tab, even after refreshing the browser.
And if you set a version to Released via Release tab, the version is set back to Unreleased by the script. Any you see the respective version in both Manage Version tab and Release tab as Unreleased (after reload of the tab), correct?
Correct.
And if you set a version to Released via Manage Version tab, then what is shown in Releases tab for this version and what in Manage Version tab (after reload of the page)? It is shown as Released or Unreleased?
BOTH Releases tab and Manage Versions tab show version as “Released” instead of the expected “Unreleased”, when code executes from the Manage Versions tab.
Please check reload of the Manage Version page, if the status is shown then as Unreleased?
refreshing the page doesn’t change anything. The version remains in “Released” status.
If you like, I can take a camstudio video clip on the situation.
Thank you for your reply,
Darryl
-
repo owner But in both scenarios the Script Runner log says “Success” because the REST API call was successful?
In the attached Simplified script, you are calling vermgr.releaseVersion(event.version, false)” and also the REST API if I am correct. Why are you calling it twice?
-
reporter Holger,
I’m calling it twice (once as vermgr.releaseVersion() and twice as REST API) because Atlassian Support said in my ticket they just closed, that .releaseVersion() cannot be trusted. And they recommended I use the REST API instead. But I found both didn’t work on the Manage Versions tab.
Darryl
-
repo owner In the log there is some debug info about SQL insert statement. Any idea where this is coming from?
-
reporter Yes, I noticed that. I looked into the Jira Logging/ https://jiratest.gvl.is.l-3com.com/secure/admin/ViewLogging.jspa
And noticed these were set to DEBUG. So I turned them to WARN instead.
net.java.ao.sql
com.atlassian.activeobjects.osgiHere is what it looks like after that was turned off:
Time (on server):
Mon Aug 31 2020 18:26:49 GMT-0500 (Central Daylight Time)
The following log information was produced by this execution. Use statements like:
log.info("...")
to record logging information.2020-08-31 18:26:49,387 INFO [scriptrunner.UnreleaseIt]: Current VersionName: TestVersion1 on Project Test Big Safari 2020-08-31 18:26:49,387 INFO [scriptrunner.UnreleaseIt]: currentUser: HahnDA 2020-08-31 18:26:49,397 INFO [event.JiraServerVersionEventListener]: [TC:244a2a6c] Version event: com.atlassian.jira.event.project.VersionUnreleaseEvent@4d58 2020-08-31 18:26:49,401 INFO [event.JiraServerVersionEventListener]: [TC:217f6325] Version event: com.atlassian.jira.event.project.VersionUnreleaseEvent@4d58 2020-08-31 18:26:49,401 INFO [event.JiraServerVersionEventListener]: [TC:9153adc0] Version event: com.atlassian.jira.event.project.VersionUnreleaseEvent@4d58 2020-08-31 18:26:49,405 INFO [scriptrunner.UnreleaseIt]: Attempt to unrelease with .releaseVersion cmd: VersionName: TestVersion1 on Project Test Big Safari 2020-08-31 18:26:49,529 INFO [scriptrunner.UnreleaseIt]: Attempt to unrelease with WebAPI cmd: VersionName: TestVersion1 on Project Test Big Safari status: Jira attempt: Jira Success
-Darryl
-
repo owner I am able to reproduce the issue in my local development environment by installing ScriptRunner and creating an event listener for VersionReleaseEvent to set the version to unreleased.
import com.atlassian.jira.event.project.VersionReleaseEvent import com.atlassian.jira.component.ComponentAccessor def versionManager = ComponentAccessor.getVersionManager() def releaseevent = event as VersionReleaseEvent def version = releaseevent.version def updatedversion = versionManager.releaseVersion( version, false) log.error "Holgers testing " + version.name + " is released = " + version.released log.error "Holgers testing " + updatedversion.name + " is released = " + updatedversion.released
It looks like in the code of Version Manager for Jira the additional call
aVersion = versionmanager.archiveVersion(aVersion, false);
creates the issue, because it persists again the whole status of the version including released=true and not only sets archived=true for that versioin, but also don’t fires the VersionReleaseEvent.I am investigating if it is okay to switch safely from
if ( null != newVersionBean.status ){ if ( newVersionBean.status == VersionBean.Status.Unreleased) { aVersion = versionmanager.releaseVersion(aVersion, false); aVersion = versionmanager.archiveVersion(aVersion, false); } else if ( newVersionBean.status == VersionBean.Status.Released) { aVersion = versionmanager.releaseVersion(aVersion, true); aVersion = versionmanager.archiveVersion(aVersion, false); } else if ( newVersionBean.status == VersionBean.Status.Archived) { aVersion = versionmanager.archiveVersion(aVersion, true); } }
to
if ( null != newVersionBean.status ){ if ( newVersionBean.status == VersionBean.Status.Unreleased && aVersion.isReleased() ) { aVersion = versionmanager.releaseVersion(aVersion, false); } else if ( newVersionBean.status == VersionBean.Status.Released && !aVersion.isReleased() ) { aVersion = versionmanager.releaseVersion(aVersion, true); } else if ( newVersionBean.status == VersionBean.Status.Archived && !aVersion.isArchived() ) { aVersion = versionmanager.archiveVersion(aVersion, true); } }
This change would solve your issue, because I am not double-setting the status release=true via
versionmanager.archiveVersion
.Would you be interested in testing a beta-release with this bugfix?
-
reporter Would you be interested in testing a beta-release with this bugfix?
Yes! :)
-
repo owner Okay, will soon create one and attach here.
One question for me is, that when you set the version to „Released“ in Manage Version tab, it will be shown as released to the user. Even though by the Event Listener it might be rolled back to unreleased within short or long time frame. This is visible to the user only after reload of the page.
What do you think? Should be acceptable, right? If I understand your use case correctly this roll back to unreleased could take some time because it would be the result of a failed release pipeline or similar. Correct?
-
repo owner - attached versionmanager-1.3.1-b1.jar
Please find attache a beta release for testing. Do not use it in production environment.
-
reporter Holger,
I installed your beta version: versionmanager-1.3.1-b1.jar
and tested with it.
The unrelease command did work. In the Manage Versions tab, I marked my Version as Released, and the script did Unrelease it for me. I could see that AFTER I refreshed the window.
However I found this error in the scriptrunner listener script log file:
Time (on server):
Mon Sep 14 2020 17:32:55 GMT-0500 (Central Daylight Time)
The following log information was produced by this execution. Use statements like:
log.info("...")
to record logging information.2020-09-14 17:32:55,452 INFO [scriptrunner.UnreleaseIt]: Current VersionName: TestVersion1 on Project Test Big Safari 2020-09-14 17:32:55,455 INFO [scriptrunner.UnreleaseIt]: currentUser: HahnDA 2020-09-14 17:32:55,502 DEBUG [ao.sql]: SELECT "SEQUENCE",ID,VERSION_ID FROM dbo.AO_6ED4FA_RM_BOARDVERSION WHERE VERSION_ID = ? 2020-09-14 17:32:55,503 INFO [event.JiraServerVersionEventListener]: [TC:844dcbd0] Version event: com.atlassian.jira.event.project.VersionUnreleaseEvent@4d58 2020-09-14 17:32:55,504 INFO [event.JiraServerVersionEventListener]: [TC:e4335bae] Version event: com.atlassian.jira.event.project.VersionUnreleaseEvent@4d58 2020-09-14 17:32:55,504 INFO [event.JiraServerVersionEventListener]: [TC:d6603303] Version event: com.atlassian.jira.event.project.VersionUnreleaseEvent@4d58 2020-09-14 17:32:55,508 DEBUG [ao.sql]: INSERT INTO dbo.AO_8BAD1B_ITEM_EVENTS (C_ID,C_TYPEID,C_ITEMID,C_TIMESTAMP,C_ITEMSID) VALUES (?,?,?,?,?) 2020-09-14 17:32:55,510 DEBUG [ao.sql]: INSERT INTO dbo.AO_8BAD1B_ITEM_EVENTS (C_ID,C_TYPEID,C_ITEMSID,C_TIMESTAMP,C_ITEMID) VALUES (?,?,?,?,?) 2020-09-14 17:32:55,514 INFO [scriptrunner.UnreleaseIt]: Attempt to unrelease with .releaseVersion cmd: VersionName: TestVersion1 on Project Test Big Safari 2020-09-14 17:32:55,839 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2020-09-14 17:32:55,840 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.project.VersionReleaseEvent, file: null javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at org.apache.http.conn.ssl.SSLSocketFactory.createLayeredSocket(SSLSocketFactory.java:573) at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:557) at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:414) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:326) at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445) at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:221) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:434) at groovyx.net.http.HTTPBuilder.request(HTTPBuilder.java:366) at groovyx.net.http.HTTPBuilder$request.call(Unknown Source) at con.scriptrunner.UnreleaseIt.UnreleaseIt.<init>(Script21.groovy:50) at con.scriptrunner.UnreleaseIt.Script21.run(Script21.groovy:69) Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target ... 17 more Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target ... 17 more
Regards,
Darryl
-
repo owner This looks like an issue within ScriptRunner or your Jira setup. I would suggest to get in contact with ScriptRunner support. I guess it is also not specific to Manage Version tab but is the same in the Releases tab.
-
repo owner - changed status to resolved
Released as version 1.3.1
-
reporter Holger, So you will not release this beta version? It does work, it just throws the error. This scriptrunner script works fine under the Jira Releases tab.
Darryl
-
repo owner As written before it is released as version 1.3.1.
For the error I suggest to fix the webservice REST call as it throws an SSL authentication error resp. you need to fix this https certificate error. Or use vermgr.releaseVersion().
Best regards, Holger
-
reporter Thank you Holger! Version 1.3.1 solves my issue. unrelease now works on Manage Versions tab.
- Log in to comment
Version Manager for Jira plugin uses the regular VersionManager API. That is why everything what is happening anywhere with versions is automatically reflected in Version Manager for Jira. There is no additional layer or business logic. Just Jira VersionManager API used.
To provide a little more detail see below. Maybe this helps to understand what might be wrong in your script.
The REST API provided by Version Manager for Jira has the following signature.
In the updateVersion method the regular versionmanger of Jira API import com.atlassian.jira.project.version.VersionManager is used.
You see Version Manager for Jira is calling versionmanager.releaseVersion.
Could you check, if your script is called when a version is changed via Version Manager for Jira UI?