---
sourceDocument: Xanadu IT Service Management
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/xanadu/it-service-management

 Release :

    - xanadu

ft:locale :

    - ja-JP

ft:publication_title :

    - Xanadu IT Service Management

ft:clusterId :

    - itsm

bundleId :

    - itsm

workflow :

    - Technology


---

# テスト API を使用してテスト結果を変更要求に追加する

# テスト API を使用してテスト結果を変更要求に追加する {#ariaid-title1}

* リリースバージョン: Xanadu
* 
* 更新日 2024年08月01日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：15分

DevOps - POST /devops/tool/{capability} API のテスト機能を使用して、 DevOps 変更要求にテスト結果を追加します。API は、 DevOps チェンジベロシティ に接続されているさまざまなツールのすべてのテストタイプで使用できます。
API の詳細については、「 [DevOps - POST /devops/tool/{capability}](https://www.servicenow.com/docs/access?context=devops-api&version=xanadu&pubname=xanadu-api-reference&section=devops-POST-tool&ft:locale=en-US)」を参照してください。Azure DevOps、GitHub、Jenkins で API を使用するには、以下のそれぞれのセクションに記載されている形式を使用する必要があります。
前提条件

必要なロール:sn_devops.admin

API で使用するテストタイプが DevOps チェンジベロシティ でテストタイプとして利用可能であり、それぞれのオーケストレーションツールにマッピングされていることを確認する必要があります。  
1. 移動先 DevOps 変更ワークスペース管理統合テストタイプ.

   クラシック UI ナビゲーションを使用することもできます DevOps統合テストタイプ.
2. \[テストタイプ\] テーブルでテストタイプが利用可能かどうかを確認します。

3. カスタムテストタイプの場合は、\[ 新規 \] を選択し、テストタイプをリストに追加します。  
   1. \[ テストタイプ \] フィールドに、テストタイプの名前を入力します。
   2. \[ テストカテゴリ \] リストから、テストタイプのカテゴリを選択します。
   3. \[保存\] を選択します。
   {#test-api-tools__ol_cv3_m5v_kbc}
4. 移動先 DevOps 変更ワークスペース管理統合テストタイプマッピング.

   クラシック UI ナビゲーションを使用することもできます DevOps統合テストタイプマッピング.
5. テストタイプがオーケストレーションツールにマッピングされているかどうかを確認します。

6. マッピングが利用できない場合は、\[ 新規 \] を選択してマッピングを作成します。  
   1. \[ テストタイプ \] リストから、マッピングするテストタイプを選択します。
   2. \[ ツール統合 \] リストから、オーケストレーションツールを選択します。
   3. \[保存\] を選択します。
   {#test-api-tools__ol_vty_hvv_kbc}
{#test-api-tools__ol_drl_ksv_kbc}

## Azure DevOps {#test-api-tools__section_q33_xyk_kbc}

Azure DevOpsパイプラインの場合は、ここに示す形式を使用して、さまざまなテストタイプの変更要求にテスト結果を追加します。  
URL サフィックスとパラメーターの形式:

    /api/sn_devops/v1/devops/tool/test?toolId=<devops_ToolID>&testType=<test_type>

* パラメーター toolId は、 DevOps チェンジベロシティ で接続および構成されたツールからの有効なツール ID である必要があります。
* パラメーター testType には、 DevOps チェンジベロシティ のテストタイプマッピングが必要です。
{#test-api-tools__ul_yps_xxm_lbc}

Body内では、テストタイプに基づいてパラメーターを渡す必要があります。  
注:  
汎用接続の場合は、以下を使用します。

* ユーザー名:devops.integration.user
* パスワード:\<devops.integration.user password\>
{#test-api-tools__ul_izs_yfg_mbc}

パフォーマンステストのパイプライン構成  
本文のサンプルパラメーター:

    {
      "name": "Perf. tests DEMO5",
      "duration": 0,
      "maximumVirtualUsers": 10,
      "throughput": "5/min",
      "maximumTime": 10000,
      "minimumTime": 5000,
      "averageTime": 7000,
      "ninetyPercent": 8000,
      "standardDeviation": 2,
    "startTime": "2023-12-14T23:31:31z",
      "finishTime": "2023-12-14T23:40:32z",
      "buildNumber": $(Build.BuildNumber),
      "stageName": "Test API Job",
      "pipelineName": "TEST-CI-PIPELINE"
    }

Now インスタンスのパフォーマンステストサマリー:

DevOps 変更要求に添付されたテストサマリー:

その他の機能テストおよび単体テストのパイプライン構成  
本文のサンプルパラメーター:

    {
      "name":" Smoke Test summary",
       "duration":0.0,
       "passedTests":1,
       "failed Tests":1,
       "skipped Tests":1,
       "blockedTests":1,
       "total Tests":4,
      "startTime": "2023-12-14T23:31:31z",
      "finishTime": "2023-12-15T23:31:31z",
      "buildNumber": $(Build. BuildNumber),
     "stageName": "Test API Job",
      "pipelineName": "TEST-CI-PIPELINE"
    }

DevOps 変更要求に添付されたテストサマリー:

## Azure DevOps YAML パイプライン {#test-api-tools__section_qxh_x2l_kbc}

サンプルパイプライン:  

    stages:
      - stage: BashScript
        jobs:
          - job: 'bash'
            steps:
            - script: echo Hello, world!
              displayName: 'BashScript'

            
      - stage: TestAPI
        dependsOn: BashScript
        jobs:
          - job: 'RESTTestAPI'
            # dependsOn: BashScript
            pool: server
            steps:
            - task: InvokeRESTAPI@1
              displayName: 'Invoke REST API: POST'
              inputs:
                connectionType: 'connectedServiceName'
                serviceConnection: 'v01 - generic connection'
                method: 'POST'
                body: |
                  {
                                "name": "Performance test summary kl2",
                                "duration": 0,
                                "maximumVirtualUsers": 10,
                                "throughput": "5/min",
                                "maximumTime": 10000,
                                "minimumTime": 5000,
                                "averageTime": 7000,
                                "ninetyPercent": 8000,
                                "standardDeviation": 2,
                                "startTime": "2023-12-14T23:31:31z",
                                "finishTime": "2023-12-14T23:40:32z",
                                "buildNumber": $(Build.BuildId),
                                "stageName": "TestAPI/RestTestAPI",
                                "pipelineName": "TESTYMLPipeline"
                              }
                urlSuffix: '/api/sn_devops/v1/devops/tool/test?toolId=<devops_ToolID>&testType=<test_type>'
                waitForCompletion: 'false'

              
リリースパイプライン

## GitHub {#test-api-tools__section_agm_wyk_kbc}

GitHubパイプラインの場合は、ここに示す形式を使用して、さまざまなテストタイプの変更要求にテスト結果を追加します。

パフォーマンステストのパイプライン構成

サンプルパイプライン:  

    name: Test API Call Perf

    on: 
      workflow_dispatch:

    jobs:
      post_api_call_perf:
        runs-on: ubuntu-latest
        
        steps:
        - name: Checkout Repository
          uses: actions/checkout@v2

        - name: post_api_call_perf
          run: |
            apiUrl="https://<your_instance>.service-now.com/api/sn_devops/v1/devops/tool/test?toolId=<devops_ToolId>&testType=<performance_test_type>"
            requestBody='{"toolId": "<devops_ToolId>", "buildNumber": '${{ github.run_number }}' , "workflow": "Test API Call Perf", "repository": "<your_GitHub_repository>", "stageName":"post_api_call_perf","pipelineName":"Test API Call Perf", "testType": "Load", "buildNumber": '${{ github.run_number }}', "buildId": '${{ github.run_id }}' , "attemptNumber" : '${{ github.run_attempt }}', "name": "GitHub Test Summary - Performance 1.0","duration": 0.0,"maximumVirtualUsers": 10,"throughput": "5/min","maximumTime": 1000,"minimumTime": 5000,"averageTime": 7000,"startTime": "2023-12-14T23:31:31z","finishTime": "2023-12-14T23:31:31z","ninetyPercent": 8000, "standardDeviation": 2.0 }'
            auth="devops.integration.user:<password> in base64 encoded"
            authHeader="Basic $auth"
            response=$(curl -X POST -H "Content-Type: application/json" -H "Authorization: $authHeader" -d "$requestBody" $apiUrl)
            exitCode=$?
            
            if [ $exitCode -eq 0 ]; then
              echo "API call successful!"
              echo "Response: $response"
            else
              echo "API call failed!"
              echo "Response: $response"
              exit 1
            fi

その他の機能テストおよび単体テストのパイプライン構成  
サンプルパイプライン:

    name: Test API Call

    on: 
      workflow_dispatch:

    jobs:
      post_api_call:
        runs-on: ubuntu-latest
        
        steps:
        - name: Checkout Repository
          uses: actions/checkout@v2

        - name: post_api_call
          run: |
            apiUrl="https://<your_instance>.service-now.com/api/sn_devops/v1/devops/tool/test?toolId=<devops_ToolID>&testType=<test_type>"
            requestBody='{"toolId": "<devops_ToolID>", "buildNumber": '${{ github.run_number }}' , "workflow": "Test API Call", "repository": "<your_GitHub_repository>", "stageName":"post_api_call","pipelineName":"TestAPICall", "testType": "Smoke", "buildNumber": '${{ github.run_number }}', "buildId": '${{ github.run_id }}' , "attemptNumber" : '${{ github.run_attempt }}', "testSummaries": [{"name": "GitHub Test Summary - smoke","passedTests": 1,"failedTests": 1,"skippedTests": 1,"ignoredTests": 0,"blockedTests": 1,"totalTests": 4,"startTime": "2023-12-14T23:31:31z","endTime": "2023-12-14T23:31:31z","duration": 0.0,"testType": "Smoke", "suites": []}] }'
            auth="devops.integration.user:<password> in base64 encoded"
            
            authHeader="Basic $auth"
            response=$(curl -X POST -H "Content-Type: application/json" -H "Authorization: $authHeader" -d "$requestBody" $apiUrl)
            exitCode=$?
            
            if [ $exitCode -eq 0 ]; then
              echo "API call successful!"
              echo "Response: $response"
            else
              echo "API call failed!"
              echo "Response: $response"
              exit 1
            fi

## Jenkins {#test-api-tools__section_pfd_5yk_kbc}

Jenkinsパイプラインの場合は、ここに示す形式を使用して、さまざまなテストタイプの変更要求にテスト結果を追加します。

パフォーマンステストのパイプライン構成  
サンプルパイプライン:

    pipeline {
        agent any
        stages {
            stage('POST API Call') {
                steps {
                    script {
                        def apiUrl = 'https://<your_instance>.service-now.com/api/sn_devops/v1/devops/tool/test?toolId=<devops_ToolID>&testType=<performance_test_type>'
                        def requestBody = [
                            name: "Performance Load tests jenkins",
                            duration: 0.0,
                            maximumVirtualUsers: 10,
                            throughput: "6/min",
                            maximumTime: 1000,
                            minimumTime: 300,
                            averageTime: 700,
                            ninetyPercent: 600,
                            standardDeviation: 2.0,
                            startTime: "2023-12-14T23:31:31z",
                            finishTime: "2023-12-14T23:40:32z",
                            buildNumber: env.BUILD_NUMBER,
                            stageName: "POST API Call",
                            pipelineName: "KLPerformanceTestPipeline"
                        ]
                        def auth = "<password>" // devops.integration.user:<password> in base64 encoded.
                        def authHeader = "Basic " + auth
                        def response = httpRequest(
                            contentType: 'APPLICATION_JSON',
                            httpMode: 'POST',
                            requestBody: groovy.json.JsonOutput.toJson(requestBody),
                            url: apiUrl,
                            customHeaders: [[name: 'Authorization', value: authHeader]]
                        )

                        if (response.status == 200 || response.status == 201) {
                            echo "API call successful!"
                            echo "Response: ${response.content}"
                        } else {
                            error "API call failed with status ${response.status}"
                        }
                    }
                }
            }
        }
    }

その他の機能テストおよび単体テストのパイプライン構成  
サンプルパイプライン:

    pipeline {
        agent any
        
        stages {
            stage('POST API Call') {
                steps {
                    script {
                        def apiUrl = 'https://<your_instance>.service-now.com/api/sn_devops/v1/devops/tool/test?toolId=<devops_ToolID>&testType=<test_type>'
                        def requestBody = [
                            name: "Smoke tests",
                            duration: 0.0,
                            passedTests: 1,
                            failedTests: 1,
                            skippedTests: 1,
                            blockedTests: 1,
                            totalTests: 4,
                            startTime: "2023-12-14T23:31:31z",
    	                    finishTime: "2023-12-15T23:31:31z",
                            buildNumber: env.BUILD_NUMBER,
                            stageName: "POST API Call",
                            pipelineName: "TestPipelineKL"
                        ]
                        
                        def auth = "<password>" // devops.integration.user:<password> in base64 encoded.
                        def authHeader = "Basic " + auth
                        
                        def response = httpRequest(
                            contentType: 'APPLICATION_JSON',
                            httpMode: 'POST',
                            requestBody: groovy.json.JsonOutput.toJson(requestBody),
                            url: apiUrl,
                            customHeaders: [[name: 'Authorization', value: authHeader]]
                        )
                        
                        if (response.status == 200 || response.status == 201) {
                            echo "API call successful!"
                            echo "Response: ${response.content}"
                        } else {
                            error "API call failed with status ${response.status}"
                        }
                    }
                }
            }
        }
    }

## テスト API の制限事項 {#test-api-tools__section_nym_dz4_kbc}

* 待機ロジックは処理されません。
* シナリオの再実行は処理できません。
{#test-api-tools__ul_g1r_2z4_kbc}

