Newman API 테스트 컬렉션을 Jenkins와 통합하고 Flock 메신저를 사용하여 보고서 게시

In this article, we will be exploring about how to run Postman collections on Jenkins with Freestyle Project. And we will try to generate our test run reports using Allure Jenkins plugin and will publish the test run status notifications to Flock messenger. 



내용물



  • Jenkins Setup
  • Step1:Install NodeJS plugin
  • Step2:Add Newman and Allure Packages
  • Step3:Create a Newman job with freestyle.

  • How to Run

  • 젠킨스 설정

    Before we get started, you’ll need to install Jenkins on your machine. If you don’t have a setup Jenkins on your machine please follow this official documentation .

    Jenkins를 설치한 후 Jenkins에서 NodeJS를 구성해야 합니다.

    1단계: NodeJS 플러그인 설치:

    Go to → Manage Jenkins → Select Manage Plugins → Select Available tab and Search Active Choice Plugin.


    플러그인의 올바른 설치를 위해 Jenkins를 설치하고 다시 시작하십시오.

    2단계: NodeJS에 Newman 및 Allure 패키지 추가

    Open Jenkins: Manage Jenkins → Global Tool Configuration → NodeJS

    Set your compatible node version. We can set multiple NodeJS versions for multiple applications.

    Make sure you follow these steps:

    • Check the “Install automatically” option
    • Select compatible Node version (NodeJs-16.2.0)
    • Add required packages in the “Global Packages to Install” section In our case, add the following packages newman newman-reporter-allure
    • Save settings.

    3단계: 자유형으로 Newman 작업을 만듭니다.

    1. Create a Freestyle job to execute Newman collections scripts.
    Open Jenkins → New Item → Enter any job name→ Choose Freestyle Project → Click on Save button

    2. Parameterising the Jenkins build for different Newman environment
    A build parameter allows us to pass data into our Jenkins jobs. Build parameters are a powerful way to make any Jenkins job more dynamic.So by using build parameters, we can pass any data we want. In our use case, we will be passing the Newman environment variables. Note: Follow this 
    tutorial , Newman 환경 변수의 고유 ID를 얻으려면.

    Extended Choice Parameter 플러그인 설치:
  • Jenkins 홈페이지에서 'Jenkins 관리'로 이동합니다.
  • 플러그인 관리로 이동합니다
  • .
  • 탭을 사용 가능으로 변경
  • 확장 선택 매개변수 검색
  • "지금 다운로드하고 다시 시작한 후 설치"를 클릭합니다
  • .
    General → Check “This project is parameterized” → Add parameter → Choice parameter → add respective choice values for parameterization [QA / Prod].
    3.Source Code Management → Check “None”
    4.Build environment → Check “Delete workspace before build starts”
    5.Build environment → Check “Provide Node & npm bin/ folder to PATH” → select NodeJs name


    6.Build → Add build step → Select Execute Shell → And Paste the below code. → Save Your config.
    eg:- newman run [collections] -e [environment] -r allure --reporter-allure-export target/allure-results --suppress-exit-code 1
    



    newman run "https://api.getpostman.com/collections/[collection_uid]?apikey=[apiKey]" \
        --environment "https://api.getpostman.com/environments/$server?apikey=[apiKey]" \ 
        -r allure --reporter-allure-export target/allure-results \ 
        -- suppress-exit-code 1
    


    참고: 고유 컬렉션 ID 및 API 키를 사용하여 셸 명령을 통해 Newman을 실행하려면 다음tutorial을 따르세요.


    Allure 및 Flock 플러그인 설치
  • Jenkins 홈페이지에서 'Jenkins 관리'로 이동합니다.
  • 플러그인 관리로 이동합니다
  • .
  • 탭을 사용 가능으로 변경
  • Flock을 검색하고 체크박스를 선택합니다
  • .
  • Allure Report를 검색하고 확인란을 선택합니다
  • .
  • "지금 다운로드하고 다시 시작한 후 설치"를 클릭합니다
  • .
    7.Post Build Action → Allure Report → Add Path (“target/allure-results”)모든 성공적인 빌드 및 보고서 파일이 지정된 $PATH 아래에 배치된 후 Allure 보고서가 생성됩니다.
    8.Post Build Action → Send Flock Notification (add flock webhook URL)
    Webhook URL을 생성하려면 이 가이드를 따르십시오.
  • https://apps.flock.com/?source=launcherbar로 이동
  • Jenkins 검색
  • Webhook URL을 생성하도록 설치 및 구성합니다.


  • 실행 방법

    Now we just have to build our job to execute our tests. And we can do so by clicking on the “Build with Parameters” button on the left side of the dashboard.

  • Go to Jenkins Job [jenkins_url/job/[#JobName]]
  • Click on Build with Parameter → Select the options that are required to be passed in the branch parameter [QA/ Prod] and click on → BUILD
  • Flock 메신저가 Jenkins 빌드 상태에 대해 알려줍니다.
  • 보고서를 보려면 무리에서 "보기"를 클릭합니다. → Jenkins로 리디렉션됩니다. [성공적인 인증 후] → Allure Report를 클릭합니다.

  • In this article we have seen how to use Jenkins to run Newman tests, generate & publish reports using Allure / Flock plugins. I hope you may have found this useful. Cheers!!

    좋은 웹페이지 즐겨찾기