繁体   English   中英

如何在Groovy中使用JIRA REST CLIENT JAVA创建版本并获取特定项目的任何版本的详细信息?

[英]How to create the version and get the details of any version of specific project using JIRA REST CLIENT JAVA in groovy?

我正在尝试在JIRA中为特定项目创建版本。下面是我的代码。我能够通过JIRA REST CLIENT JAVA Java库成功连接JIRA,但现在想要获得任何版本的信息,createversion只需执行几个操作即可。

import com.atlassian.jira.rest.client.api.JiraRestClient
import com.atlassian.jira.rest.client.api.JiraRestClientFactory
//import com.atlassian.jira.rest.client.api.domain.User
import com.atlassian.jira.rest.client.api.domain.Version
//import com.atlassian.jira.rest.client.api.domain.input.VersionInput
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory
import com.atlassian.util.concurrent.Promise

class Jira {
  private static final String JIRA_URL = "https://jira.test.com"
  private static final String JIRA_ADMIN_USERNAME = "ABCDE"
  private static final String JIRA_ADMIN_PASSWORD = "xxxxxx"

  static void main(String[] args) throws Exception
  {
    // Construct the JRJC client
    System.out.println(String.format("Logging in to %s with username '%s' and password '%s'", JIRA_URL, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD))
    JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory()
    URI uri = new URI(JIRA_URL)
    JiraRestClient client = factory.createWithBasicHttpAuthentication(uri, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD)
   // client.withCloseable {
    //  it.projectClient.getProject("ABCD").claim().versions.each { println it }
   // }

    // Invoke the JRJC Client
    //Promise<User> promise = client.getUserClient().getUser(JIRA_ADMIN_USERNAME)
    //User user = promise.claim()

    Promise<Version> promise = client.getVersionRestClient().getVersion(1234)
    //Version version = promise.claim()

    // Print the result
    System.out.println(String.format("Your user's email address is: %s\r\n", user.getEmailAddress()))
  }
}

我能够执行一些任务,例如获取任何用户ID的电子邮件地址。我正在groovy中尝试此操作

package com.temp.jira

import com.atlassian.jira.rest.client.api.JiraRestClient
import com.atlassian.jira.rest.client.api.JiraRestClientFactory
import com.atlassian.jira.rest.client.api.domain.BasicProject
import com.atlassian.jira.rest.client.api.domain.Issue
import com.atlassian.jira.rest.client.api.domain.SearchResult
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory
import com.atlassian.util.concurrent.Promise
/**
 * Created on 7/21/2017.
 */
class Test {

    private static final String JIRA_URL = "https://jira.test.com"
    private static final String JIRA_ADMIN_USERNAME = "ABCDEF"
    private static final String JIRA_ADMIN_PASSWORD = "*****"
    private static final String JIRA_PROJECT = "ABCD"

    static void main(String[] args) throws Exception
    {
        // Construct the JRJC client
        System.out.println(String.format("Logging in to %s with username '%s' and password '%s'", JIRA_URL, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD))
        JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory()
        URI uri = new URI(JIRA_URL)
        JiraRestClient client = factory.createWithBasicHttpAuthentication(uri, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD)


        for (BasicProject project : client.getProjectClient().getProject(JIRA_PROJECT).claim()) {
            System.out.println(project.getKey() + ": " + project.getName())

        }

       Promise<SearchResult> searchJqlPromise = client.getSearchClient().searchJql("project = $JIRA_PROJECT AND status in (Closed, Completed, Resolved) ORDER BY assignee, resolutiondate");

       for (Issue issue : searchJqlPromise.claim().getIssues()) {
          System.out.println(issue.getId())
       }

         // Done
        System.out.println("Example complete. Now exiting.")
        System.exit(0)
    }
}

坚持使用jira rest客户端api,因为您可以从创建者fJira提供的输入权限。

摘自我工作的Groovy代码:

/**
 * Retrieves the latest unreleased version for the given project.
 * @param projectId Given project
 * @return latest unreleased version
 */
private Version getVersion(String projectId)
{
    def project = restClient.projectClient.getProject(projectId).claim()
    def unreleasedVersions = project
        .getVersions()
        .findAll { version ->
            version.released == false
        }

    if (unreleasedVersions.size() != 1) {
        throw new RuntimeException('There are zero or more unreleased versions.')
    }

    unreleasedVersions.get(0)
}

/**
 * Creates a new, undeployed version for the given project.
 * @param projectId Given project
 */
private void createVersion(String projectId)
{
    def versionInputBuilder = new VersionInputBuilder(projectId)
    versionInputBuilder.released = false
    versionInputBuilder.name = incrementVersion(capturedVersion.name)
    versionInputBuilder.description = 'Bugfixing'
    versionInputBuilder.startDate = DateTime.now()

    def promise = restClient.versionRestClient.createVersion(versionInputBuilder.build())
    trackCompletion(promise)
}

我的代码中没有的是获得特定版本,但是当您将版本的数据类型更改为字符串时,您的注释代码应该可以工作。

我以以下方式创建了脚本,并且能够创建,更新和删除版本

import com.atlassian.jira.rest.client.api.JiraRestClient
import com.atlassian.jira.rest.client.api.VersionRestClient
import com.atlassian.jira.rest.client.api.domain.Version
import com.atlassian.jira.rest.client.api.domain.input.VersionInput
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory
import com.atlassian.util.concurrent.Promise
import org.codehaus.jettison.json.JSONException
import org.joda.time.DateTime
import java.util.concurrent.ExecutionException
class VersionClient {
    private static final String JIRA_URL = "https://jira.test.com"
    private static final String JIRA_ADMIN_USERNAME = "ABCDEF"
    private static final String JIRA_ADMIN_PASSWORD = "******"
    private static final String JIRA_PROJECT = "TEST"
     static void main(String[] args)
             throws URISyntaxException, InterruptedException, ExecutionException, JSONException {
        // Initialize REST Client
        final AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory()
        final URI uri = new URI("$JIRA_URL")
        final JiraRestClient jiraRestClient = factory.createWithBasicHttpAuthentication(uri, "$JIRA_ADMIN_USERNAME", "$JIRA_ADMIN_PASSWORD")
        // Get specific client instances
        VersionRestClient versionClient = jiraRestClient.getVersionRestClient()
        // Create Version
        VersionInput versionInput = new VersionInput("$JIRA_PROJECT", "TEST 1.2.8", "Test Version", new DateTime(), false, false)
        Promise<Version> version = versionClient.createVersion(versionInput)
        Version versionObj = version.get()
        System.out.println("Created Version:" + versionObj.getName())
         // Invoke the JRJC Client
         Promise<Version> promise = versionClient.getVersion(versionObj.getSelf())
         Version versionid = promise.claim()
         // Print the result
         System.out.println(String.format("Version id is: %s\r\n", versionid.getId() + " and URI:" + versionid.getSelf()))


        // Release Version using Update
         versionClient.updateVersion(versionid.getSelf(),new VersionInput("$JIRA_PROJECT", "TEST 1.2.8", "Test Version", new DateTime(), false, true))

        // Delete the Version
         versionClient.removeVersion(versionid.getSelf(), null, null).claim()
         System.out.println("Deleted Version")

 }
}

暂无
暂无

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

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