You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Postman Newman Jenkins Java集成:测试结果同步至Jira的技术实现疑问

Answers to Your Newman-Jenkins-Jira Integration Questions

Hey there! Let's break down your questions one by one based on my experience with these tools:

1. Where to store Newman test result files? Can we use Jenkins workspace?

Absolutely yes — the Jenkins workspace is the perfect place for this. When you run a Newman command in a Jenkins job, it executes directly in the job's workspace directory by default. You can explicitly specify the output path for the JSON results to ensure it lands here, using a command like:

newman run your-collection.json -e your-env.json --reporters json --reporter-json-export newman-test-results.json

This will save the newman-test-results.json file right in the Jenkins workspace. Since your Java project will run as part of the same Jenkins job (or have access to the workspace path), it can easily read this file later.

2. Is running a Jar to process JSON results and push to Jira API feasible?

100% feasible — this is a clean, modular approach. Here's the core workflow:

  • Your Java Jar reads the Newman JSON result file from the Jenkins workspace.
  • It parses key data points: test case names, pass/fail statuses, error messages (for failed tests), execution timestamps, etc.
  • It constructs HTTP requests to Jira's REST API (e.g., to create test execution issues, update existing issue statuses, or add comments with test details).
  • In Jenkins, you just add a post-build step to run the Jar with:
    java -jar jira-test-pusher.jar ./newman-test-results.json
    

Just make sure your Jenkins agent has Java installed, and the Jar has access to the workspace file path (no permission issues). This approach keeps your Newman execution and Jira sync logic separate, making it easier to maintain each part.

3. Should the Java project use Maven for building?

Highly recommended, though you could use Gradle too. Maven simplifies two critical parts of this project:

  • Dependency management: You'll need libraries for JSON parsing (Jackson/Gson), HTTP requests (OkHttp/Retrofit), and possibly Jira API wrappers. Maven handles downloading and managing these dependencies automatically.
  • Packaging: Using plugins like maven-assembly-plugin or maven-shade-plugin, you can build a single "fat Jar" that includes all dependencies. This means you don't have to install any extra libraries on the Jenkins server — just drop the Jar and run it.

If your project is extremely simple (like a few classes with no external dependencies), you could manually compile and package it, but Maven will save you time in the long run, especially if you need to update dependencies or add features later.

While I can't share external articles, here are actionable implementation directions to get you started:

  • Newman JSON structure: Run Newman locally with the JSON reporter to generate a sample result file. Look for the run.executions array — this contains every test case's details, including test (name), assertions (pass/fail status), and error (failure details if applicable). You can map this structure to Java classes for easy parsing.
  • Jira API basics: Use Jira's REST API for core actions:
    • Create a test execution issue: POST /rest/api/2/issue (with a JSON payload defining issue type, project, summary, etc.)
    • Update an existing issue (e.g., mark a test case as failed): PUT /rest/api/2/issue/{issueIdOrKey}
    • Add a comment with test results: POST /rest/api/2/issue/{issueIdOrKey}/comment
    • Authenticate using an API token (preferred over password) with basic auth: encode your-jira-email:your-api-token in Base64 and add it to the Authorization header.
  • Java code snippets:
    • Parse Newman JSON with Jackson:
      ObjectMapper mapper = new ObjectMapper();
      NewmanTestResults results = mapper.readValue(new File("newman-test-results.json"), NewmanTestResults.class);
      
      (You'll need to define NewmanTestResults and related nested classes to match the JSON structure.)
    • Call Jira API with OkHttp:
      OkHttpClient client = new OkHttpClient();
      String auth = Base64.getEncoder().encodeToString(("your-email:your-api-token").getBytes());
      Request request = new Request.Builder()
          .url("https://your-jira-instance/rest/api/2/issue")
          .addHeader("Authorization", "Basic " + auth)
          .addHeader("Content-Type", "application/json")
          .post(RequestBody.create(jiraPayloadJson, MediaType.get("application/json")))
          .build();
      Response response = client.newCall(request).execute();
      

内容的提问来源于stack exchange,提问作者whatismyname123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 18:17:33