diff --git a/README.md b/README.md index d2fa3cb..42eaaef 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ + [Get Issue Event](#get-issue-event) * [SCANNING](#scanning) + [Scan Artifact](#scan-artifact) + + [Scan Build](#scan-build) # Install @@ -213,3 +214,13 @@ scanning = xray_rest_client.scanning response = scanning.scan_artifact("docker://image_name:image_tag") print(response.json()) ``` +### Scan Build +```python +scanning = xray_rest_client.scanning +# scan build v1 +response = scanning.scan_build("build_name", "build_number") +# scan build v2 +# Starting from Xray version 3.42.3 +response = scanning.scan_build("build_name", "build_number", api_version='v2') +print(response.json()) +``` diff --git a/xray/scanning.py b/xray/scanning.py index c4966f5..ce0760f 100644 --- a/xray/scanning.py +++ b/xray/scanning.py @@ -23,4 +23,35 @@ def scan_artifact(self, component_id): ) return response - + def scan_build(self, build_name, build_number, api_version='v1'): + """ + Invokes scanning of a build that was uploaded to Artifactory as requested by a CI server + :param build_name: + :param build_number: + :param api_version: api/v2 starting from Xray version 3.42.3 + :return: + """ + assert api_version in ['v1', 'v2'] + url = '' + json_data = {} + if api_version == 'v1': + url = self.base_url + "/api/v1/scanBuild" + json_data = { + "buildName": build_name, + "buildNumber": build_number, + "rescan": True, + "filters": { + "includeLicenses": True + } + } + elif api_version == 'v2': + url = self.base_url + "/api/v2/ci/build" + json_data = { + "buildName": build_name, + "buildNumber": build_number + } + response = self.rest_post( + url, + json_data=json_data + ) + return response