テスト API を使用してテスト結果を変更要求に追加する
DevOps - POST /devops/tool/{capability} API のテスト機能を使用して、 DevOps 変更要求にテスト結果を追加します。API は、 DevOps チェンジベロシティ に接続されているさまざまなツールのすべてのテストタイプで使用できます。
API の詳細については、「 DevOps - POST /devops/tool/{capability}」を参照してください。Azure DevOps、GitHub、Jenkins で API を使用するには、以下のそれぞれのセクションに記載されている形式を使用する必要があります。
前提条件
必要なロール:sn_devops.admin
API で使用するテストタイプが DevOps チェンジベロシティ でテストタイプとして利用可能であり、それぞれのオーケストレーションツールにマッピングされていることを確認する必要があります。
- 移動先 .
クラシック UI ナビゲーションを使用することもできます .
- [テストタイプ] テーブルでテストタイプが利用可能かどうかを確認します。
- カスタムテストタイプの場合は、[ 新規 ] を選択し、テストタイプをリストに追加します。
- [ テストタイプ ] フィールドに、テストタイプの名前を入力します。
- [ テストカテゴリ ] リストから、テストタイプのカテゴリを選択します。
- [保存] を選択します。
- 移動先 .
クラシック UI ナビゲーションを使用することもできます .
- テストタイプがオーケストレーションツールにマッピングされているかどうかを確認します。
- マッピングが利用できない場合は、[ 新規 ] を選択してマッピングを作成します。
- [ テストタイプ ] リストから、マッピングするテストタイプを選択します。
- [ ツール統合 ] リストから、オーケストレーションツールを選択します。
- [保存] を選択します。
Azure DevOps
Azure DevOpsパイプラインの場合は、ここに示す形式を使用して、さまざまなテストタイプの変更要求にテスト結果を追加します。
/api/sn_devops/v1/devops/tool/test?toolId=<devops_ToolID>&testType=<test_type>- パラメーター toolId は、 DevOps チェンジベロシティ で接続および構成されたツールからの有効なツール ID である必要があります。
- パラメーター testType には、 DevOps チェンジベロシティ のテストタイプマッピングが必要です。
Body内では、テストタイプに基づいてパラメーターを渡す必要があります。
- ユーザー名:devops.integration.user
- パスワード:<devops.integration.user password>
パフォーマンステストのパイプライン構成
{
"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 パイプライン
サンプルパイプライン:
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
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
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 の制限事項
- 待機ロジックは処理されません。
- シナリオの再実行は処理できません。