简体   繁体   English

如何从Groovy设置JIRA票证的版本字段

[英]How to set the version fields of a JIRA ticket from Groovy

I'm using JIRA 7.1.4 Server and under Behaviours I'm trying to create a Groovy Initialiser Function for setting default values of form fields, so when the user tries to create a new ticket, some fields are already filled in with default values. 我正在使用JIRA 7.1.4服务器并且在行为下我正在尝试创建一个Groovy Initialiser函数来设置表单字段的默认值,因此当用户尝试创建新票证时,某些字段已经填入了默认值。 This is what I have so far: 这是我到目前为止:

import com.atlassian.jira.component.ComponentAccessor

def versionManager = ComponentAccessor.getVersionManager()
def versions = versionManager.getVersionsUnreleased(issueContext.projectObject.id, false)
getFieldById("affectedVersion").setFormValue([versions.first().id])
getFieldById("description").setFormValue([versions.first().id])

When the dialog for creating a new JIRA ticket opens, this script successfully sets the "Description" field to the right version id (only for debugging purposes), but the "Affects Version/s" field remains empty for some reason. 当打开创建新JIRA票证的对话框时,此脚本会成功将“Description”字段设置为正确的版本ID(仅用于调试目的),但“Affects Version / s”字段由于某种原因仍为空。

I think the id of the "Affects Version/s" field is OK, because I got it from JQL, so eg the following query displays correct information: 我认为“Affects Version / s”字段的id是正常的,因为我是从JQL获得的,所以例如以下查询显示正确的信息:

project = "--------" and affectedVersion is EMPTY

Therefore I assume that I'm trying to set the value of the version field incorrectly, but cannot figure out the mistake. 因此我假设我正在尝试错误地设置版本字段的值,但无法弄清楚错误。 The above Groovy script is based on this example , but the script might be wrong, and I was not able to find more information about getFieldById or setFormValue here either. 上面的Groovy脚本基于这个例子 ,但脚本可能是错误的,我也无法在这里找到有关getFieldByIdsetFormValue更多信息。

Can anyone give a working example of setting JIRA's "Affects Version/s" or "Fix Version/s" fields from Groovy? 任何人都可以举一个从Groovy设置JIRA的“Affects Version / s”或“Fix Version / s”字段的工作示例吗?

If you setting fixversion on issue create step in workflow. 如果在问题上设置fixversion,请在工作流程中创建步骤。 You need to put this script into first post function(before issue create). 您需要将此脚本放入第一个post函数(在创建问题之前)。

import com.atlassian.jira.component.ComponentAccessor
def versionManager = ComponentAccessor.getVersionManager()
def versions = versionManager.getVersionsUnreleased(issue.getProjectObject().getId(), false)
issue.setAffectedVersions([versions.first()])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM