Skip to content

Commit e75fff5

Browse files
Merge pull request #14 from ServiceNow/scratch/release_5_1_0
2 parents cd0507b + 35b2b95 commit e75fff5

17 files changed

+674
-41
lines changed

README.md

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,19 @@ npm unlink .
5555
### Building Docker Image
5656

5757
```sh
58-
docker build -t servicenowdocker/sndevops:4.0.0 .
58+
docker build -t servicenowdocker/sndevops:5.1.0 .
5959
```
6060

6161
```sh
62-
docker push servicenowdocker/sndevops:4.0.0
62+
docker push servicenowdocker/sndevops:5.1.0
6363
```
6464

6565
## Integrating with GitLab
66-
67-
[Example gitlab project](/gitlab-ci.yml)
66+
[Example Gitlab project](/gitlab-ci.yml)
67+
## Integrating with GitHub
68+
[Example Github project](/github-ci.yml)
69+
## Integrating with Harness
70+
[Example Harness project](/harness-ci.yml)
6871

6972

7073
### Env variables
@@ -75,6 +78,23 @@ SNOW_TOKEN = <servicenow-tool-token>
7578
SNOW_TOOLID = <servicenow-tool-id>
7679
```
7780

81+
### Additonal Env variables
82+
```
83+
CI_PIPELINE_ID: <pipeline-id>
84+
CI_API_V4_URL: <pipeline-url>
85+
CI_JOB_ID: <pipeline-execution-id>
86+
CI_PROJECT_PATH: <repository-path>
87+
CI_REPOSITORY_NAME: <repository-name>
88+
CI_RUN_ATTEMPT: <pipeline-attempt-number>
89+
CI_PROJECT_TITLE: <pipeline-name>
90+
```
91+
92+
### Optional Env variables
93+
```
94+
CI_COMMIT_BRANCH: <commit-branch>
95+
CI_WORKFLOW_NAME: <workflow-name>
96+
```
97+
7898
**Example with passing all ServiceNow information via commandline**
7999
```yaml
80100

@@ -85,7 +105,7 @@ stages:
85105

86106
package:
87107
stage: package
88-
image: servicenowdocker/sndevops:4.0.0
108+
image: servicenowdocker/sndevops:5.1.0
89109
script:
90110
- sndevopscli create artifact -a '[{"name":"artifact-name-$CI_JOB_ID","repositoryName":"artifact-repo-name" ,"version":"1.3.0"}]'
91111
- sndevopscli create package -n "package-name" -a '[{"name":"artifact-name-$CI_JOB_ID","repositoryName":"artifact-repo-name" ,"version":"1.3.0"}]
@@ -97,7 +117,7 @@ stages:
97117

98118
package:
99119
stage: package
100-
image: servicenowdocker/sndevops:4.0.0
120+
image: servicenowdocker/sndevops:5.1.0
101121
script:
102122
- sndevopscli create artifact -u <serviceno-url> -t <tool-id> --token <tool-token> -a '[{"name":"artifact-name-$CI_JOB_ID","repositoryName":"artifact-repo-name" ,"version":"1.3.0"}]'
103123
- sndevopscli create package -u <serviceno-url> -t <tool-id> --token <tool-token> -n "package-mame" -a '[{"name":"artifact-name-$CI_JOB_ID","repositoryName":"artifact-repo-name" ,"version":"1.3.0"}]
@@ -121,10 +141,20 @@ stages:
121141

122142
ServiceNow DevOps Change:
123143
stage: DevOpsChangeApproval
124-
image: servicenowdocker/sndevops:4.0.0
144+
image: servicenowdocker/sndevops:5.1.0
125145
script:
126146
- sndevopscli create change -p '{"changeStepDetails":{"timeout":3600,"interval":100},"attributes":{"short_description":"Automated Software Deployment","description":"Automated Software Deployment.","assignment_group":"XXXXXXX","implementation_plan":"Software update is tested and results can be found in Test Summaries Tab.","backout_plan":"When software fails in production, the previous software release will be re-deployed.","test_plan":"Testing if the software was successfully deployed or not"}}'
127147

148+
149+
-p: [optional]
150+
Change Attributes payload in JSON format
151+
152+
-ctx: [optional]
153+
Additional context parameters in JSON format. These details will be used to build the request for the DevOps Change API
154+
155+
-w: [optional]
156+
Specify for the pipeline to wait for change creation and approval. By default, the pipeline will be waiting until the change creation and it's approval
157+
128158
changeStepDetails: [optional]
129159
It holds the timeout and interval details.
130160

@@ -151,16 +181,47 @@ stages:
151181

152182
ServiceNow DevOps Sonar Scan Results:
153183
stage: DevOpsSonarStage
154-
image: servicenowdocker/sndevops:4.0.0
184+
image: servicenowdocker/sndevops:5.1.0
155185
script:
156-
- sndevopscli create sonar -url 'https://sonarcloud.io' -projectKey 'xxxxxxx'
186+
- sndevopscli create sonar -url 'https://sonarcloud.io' -projectKey 'xxxxxxx' -branch 'master'
157187

158188
url: [mandatory]
159189
This specifies the sonar url.
160190

161191
projectKey: [mandatory]
162192
This specifies the sonar project key.
163193

194+
branch: [optional]
195+
This specifies the branch on which the Sonar scan was executed. By default, it matches the branch for which the build was run. Note, for Harness, the branch option is required if CI_COMMIT_BRANCH is not provided.
196+
197+
```
198+
199+
**Example of Registring Security scan results in ServiceNow via commandline**
200+
```yaml
201+
202+
This custom step needs to be added at job level to register security scan results in ServiceNow instance.
203+
204+
stages:
205+
- DevOpsSecurityScanStage
206+
207+
ServiceNow DevOps Security Scan Results:
208+
stage: DevOpsSecurityScanStage
209+
image: servicenowdocker/sndevops:5.1.0
210+
script:
211+
- sndevopscli create securityScan -p "{\"pipelineInfo\":{\"buildNumber\":\"${CI_PIPELINE_ID}\",\"pipelineExecutionUrl\":\"${CI_PIPELINE_URL}\" },\"securityResultAttributes\":{ \"scanner\":\"Veracode\",\"applicationName\":\"PetStoreAPI-Github\",\"buildVersion\":\"\",\"securityToolId\":\"\"}}"
212+
213+
214+
-p: [mandatory]
215+
It the payload of security result attributes. The payload will have attributes as follows:
216+
buildNumber: CI_PIPELINE_ID (mandatory)
217+
pipelineExecutionUrl: CI_PIPELINE_URL (mandatory)
218+
scanner: Scanning tool and is required e.g. Checkmarx One.
219+
projectName/projectId: Name/Id of your Checkmarx One project and is required. This attribute is applicable only for Checkmarx One.
220+
applicationName: Name of your Veracode application and is required. This attribute is applicable only for Veracode.
221+
buildVersion": Veracode Scan name / build version and is optional. This attribute is applicable only for Veracode.
222+
scanId: Checkmarx One scan id and is optional. This attribute is applicable only for Checkmarx One.
223+
securityToolId: Security tool onboarded in ServiceNow (sys_id of the onboarded security tool) and is optional.
224+
164225
```
165226

166227
**Example of get change for ServiceNow via commandline**
@@ -173,7 +234,7 @@ stages:
173234

174235
ServiceNow DevOps Get Change:
175236
stage: DevOpsGetChange
176-
image: servicenowdocker/sndevops:4.0.0
237+
image: servicenowdocker/sndevops:5.1.0
177238
script:
178239
- sndevopscli get change -p "{\"buildNumber\":${CHG_JOB_ID},\"stageName\":\"ServiceNow DevOps Change Step\",\"pipelineName\":\"GitlabDockerGetAndUpdateChange\"}"
179240

@@ -209,9 +270,9 @@ stages:
209270

210271
ServiceNow DevOps Update Change:
211272
stage: DevOpsUpdateChangeStage
212-
image: servicenowdocker/sndevops:4.0.0
273+
image: servicenowdocker/sndevops:5.1.0
213274
script:
214-
- sndevopscli update change -n 'CHGXXXXXX' -p "{\"short_description\":\"G Venkata12345 Automated Software Deployment\",\"description\":\"Automated Software Deployment.\",\"assignment_group\":\"XXXXX\",\"implementation_plan\":\"Software update is tested and results can be found in Test Summaries Tab.\",\"backout_plan\":\"When software fails in production, the previous software release will be re-deployed.\",\"test_plan\":\"Testing if the software was successfully deployed or not\"}"
275+
- sndevopscli update change -n 'CHGXXXXXX' -p "{\"short_description\":\"Automated Software Deployment\",\"description\":\"Automated Software Deployment.\",\"assignment_group\":\"XXXXX\",\"implementation_plan\":\"Software update is tested and results can be found in Test Summaries Tab.\",\"backout_plan\":\"When software fails in production, the previous software release will be re-deployed.\",\"test_plan\":\"Testing if the software was successfully deployed or not\"}"
215276

216277
-n [Not mandatory if we have sndevopschg.json in our pipeline yml]: It stands for changeRequestNumber. The change request number to identify a unique change request.
217278
Precedence of choosing changeRequestNumber:
@@ -236,9 +297,9 @@ stages:
236297

237298
ServiceNow DevOps Change Step:
238299
stage: changeapproval
239-
image: servicenowdocker/sndevops:4.0.0
300+
image: servicenowdocker/sndevops:5.1.0
240301
script:
241-
- sndevopscli create change -p "{\"changeStepDetails\":{\"timeout\":3600,\"interval\":100},\"autoCloseChange\":true,\"attributes\":{\"short_description\":\"G Venkata Automated Software Deployment\",\"description\":\"Automated Software Deployment.\",\"assignment_group\":\"xxxxxxxx\",\"implementation_plan\":\"Software update is tested and results can be found in Test Summaries Tab.\",\"backout_plan\":\"When software fails in production, the previous software release will be re-deployed.\",\"test_plan\":\"Testing if the software was successfully deployed or not\"}}"
302+
- sndevopscli create change -p "{\"changeStepDetails\":{\"timeout\":3600,\"interval\":100},\"autoCloseChange\":true,\"attributes\":{\"short_description\":\"Automated Software Deployment\",\"description\":\"Automated Software Deployment.\",\"assignment_group\":\"xxxxxxxx\",\"implementation_plan\":\"Software update is tested and results can be found in Test Summaries Tab.\",\"backout_plan\":\"When software fails in production, the previous software release will be re-deployed.\",\"test_plan\":\"Testing if the software was successfully deployed or not\"}}"
242303

243304
autoCloseChange: [optional] : Boolean value
244305

github-ci.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: GithubAction
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
permissions:
10+
contents: read
11+
env:
12+
SNOW_URL: ${{ secrets.SNOW_URL }}
13+
SNOW_TOKEN: ${{ secrets.SNOW_TOKEN }}
14+
SNOW_TOOLID: ${{ secrets.SNOW_TOOLID }}
15+
# These are the optional env variables
16+
#CI_PIPELINE_ID: ${{ github.run_id }}
17+
#CI_API_V4_URL: ${{ github.server_url }}
18+
#CI_JOB_ID: ${{ github.run_id }}
19+
#CI_PROJECT_PATH: ${{ github.job }}
20+
#CI_REPOSITORY_NAME: ${{ github.repository }}
21+
#CI_RUN_ATTEMPT: ${{ github.run_attempt }}
22+
#CI_PROJECT_TITLE: ${{ github.repository }}/${{github.workflow}}
23+
#CI_COMMIT_BRANCH: ${{ github.ref_name }}
24+
#CI_WORKFLOW_NAME: ${{ github.workflow }}
25+
26+
jobs:
27+
build:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Set up JDK 17
31+
run: |
32+
echo 'hello'
33+
34+
ServiceNowDevOpsChange:
35+
runs-on: ubuntu-latest
36+
needs: build
37+
container:
38+
image: servicenowdocker/sndevops:5.1.0
39+
env:
40+
CI_JOB_NAME: "ServiceNowDevOpsChange"
41+
42+
steps:
43+
- name: create change
44+
run: |
45+
sndevopscli create change -p "{\"changeStepDetails\":{\"timeout\":3600,\"interval\":10},\"autoCloseChange\":true,\"attributes\":{\"short_description\":\"G Venkata Automated Software Deployment\",\"description\":\"Automated Software Deployment.\",\"assignment_group\":\"a715cd759f2002002920bde8132e7018\",\"implementation_plan\":\"Software update is tested and results can be found in Test Summaries Tab.\",\"backout_plan\":\"When software fails in production, the previous software release will be re-deployed.\",\"test_plan\":\"Testing if the software was successfully deployed or not\"}}"
46+
47+
ServiceNowUpdateDevOpsChange:
48+
runs-on: ubuntu-latest
49+
needs: ServiceNowDevOpsChange
50+
container:
51+
image: servicenowdocker/sndevops:5.1.0
52+
env:
53+
CI_JOB_NAME: "ServiceNowDevOpsChange"
54+
55+
steps:
56+
- name: update change
57+
run: |
58+
sndevopscli update change -p "{\"short_description\":\"Updated Automated Software Deployment\",\"description\":\"Automated Software Deployment.\",\"assignment_group\":\"a715cd759f2002002920bde8132e7018\",\"implementation_plan\":\"Software update is tested and results can be found in Test Summaries Tab.\",\"backout_plan\":\"When software fails in production, the previous software release will be re-deployed.\",\"test_plan\":\"Testing if the software was successfully deployed or not\"}"
59+
60+
ArtifactAndPackage:
61+
runs-on: ubuntu-latest
62+
needs: build
63+
container:
64+
image: servicenowdocker/sndevops:5.1.0
65+
env:
66+
CI_JOB_NAME: "ArtifactAndPackage"
67+
steps:
68+
- name: create artifact
69+
run: |
70+
sndevopscli create artifact -a "[{\"name\": \"com:customactiondemo\",\"version\": \"1.${{ github.run_number }}\",\"semanticVersion\": \"1.${{ github.run_number }}.0\",\"repositoryName\": \"${{ github.repository }}\"}]"
71+
sndevopscli create package -n "Test_Package" -a "[{\"name\": \"com:customactiondemo\",\"version\": \"1.${{ github.run_number }}\",\"semanticVersion\": \"1.${{ github.run_number }}.0\",\"repositoryName\": \"${{ github.repository }}\"}]"
72+
73+
ServiceNowDevOpsSonarScanResults:
74+
name: ServiceNowDevOpsSonarScanResults
75+
needs: ArtifactAndPackage
76+
runs-on: ubuntu-latest
77+
container:
78+
image: servicenowdocker/sndevops:5.1.0
79+
env:
80+
CI_JOB_NAME: "ServiceNowDevOpsSonarScanResults"
81+
steps:
82+
- name: devops soanr results
83+
run: |
84+
sndevopscli create sonar -url 'https://sonarcloud.io' -projectKey 'xxxxxxx'
85+
86+
ServiceNowDevOpsSecurityScan:
87+
name: ServiceNowDevOpsSecurityScan
88+
runs-on: ubuntu-latest
89+
needs: build
90+
container:
91+
image: servicenowdocker/sndevops:5.1.0
92+
steps:
93+
- name: security scan
94+
run: |
95+
sndevopscli create securityScan -p "{ \"pipelineInfo\": { \"runId\": \"${{ github.run_id }}\", \"runNumber\": \"${{ github.run_number }}\", \"runAttempt\": \"${{ github.run_attempt }}\", \"job\": \"ServiceNowDevOpsSecurityScan\", \"workflow\": \"${{ github.workflow }}\", \"repository\": \"${{github.repository}}\" }, \"securityResultAttributes\": { \"scanner\": \"Veracode\", \"applicationName\": \"PetStoreAPI-Github\",\"buildVersion\": \"\", \"securityToolId\": \"\"}}"

gitlab-ci.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
image: servicenowdocker/sndevops:4.0.0
1+
image: servicenowdocker/sndevops:5.1.0
22
stages:
33
- pre-build
44
- build
55
- sonar
6+
- securityscan
67
- changeapproval
78
- getchange
89
- updatechange
@@ -26,6 +27,12 @@ ServiceNow DevOps SonarScan Results:
2627
script:
2728
- sndevopscli create sonar -url 'https://sonarcloud.io' -projectKey 'xxxxxxx'
2829

30+
31+
ServiceNow DevOps Security Scan Results:
32+
stage: securityscan
33+
script:
34+
- sndevopscli create securityScan -p "{\"pipelineInfo\":{\"buildNumber\":\"${CI_JOB_ID}\", \"stageName\":\"ServiceNow DevOps Security Scan Results\",\"taskExecutionUrl\":\"${CI_JOB_URL}\" },\"securityResultAttributes\":{ \"scanner\":\"Veracode\",\"applicationName\":\"PetStoreAPI-Github\",\"buildVersion\":\"\",\"securityToolId\":\"\"}}"
35+
2936
ServiceNow DevOps Change Step:
3037
stage: changeapproval
3138
variables:

0 commit comments

Comments
 (0)