Implementieren Sie anwenderdefinierte Aktionen für Pipelines mit dem generischen Docker-Container-Image
Verwenden Sie die anwenderdefinierten Aktionen ServiceNow, um Daten im Zusammenhang mit der Erstellung von Change-Anforderungen, Sonar-Scans, Artefaktregistrierungen und Paketregistrierungen in Ihrer Pipeline mithilfe des generischen Container-Image Docker zu sammeln.
Docker Ein Image ist ein Softwarepaket, das zum Ausführen einer Anwendung verwendet werden kann. Diese Abbildung zeigt, wie ein Container instanziiert werden soll und welche Softwarekomponenten ausgeführt werden müssen. Docker Container ist eine virtuelle Umgebung, die Anwendungscode und alle Abhängigkeiten kombiniert, die zum Ausführen der Anwendung erforderlich sind. Weitere Informationen zu Docker finden Sie in der Docker-Dokumentation.
Umgebungsvariablen für GitLab
- SNOW_TOKEN: ServiceNow Tokennummer. Es ist eine maskierte Variable und wird nicht in den Aufträgen angezeigt.
- SNOW_TOOLID: ServiceNow Tool-ID.
- SNOW_URL: Instanz-URL ServiceNow.
Wenn Sie die Variable SNOW_TOKEN hinzufügen, können Sie das Token abrufen, indem Sie im Tooldatensatz in der Tabelle „Tool“ [sn_devops_tool] auf die Schaltfläche Token kopieren klicken.
Die Umgebungsvariablen müssen mit den Werten aktualisiert werden, die im Popup-Fenster Webhooks manuell konfigurieren auf der Datensatzseite des Tools verfügbar sind. Einzelheiten zum Anzeigen der Verbindungsdetails finden Sie unter Konfigurieren Sie Webhooks über den Tooldatensatz und Konfigurieren Sie Webhooks manuell in GitLab..
Umgebungsvariablen für GitHub Actions
Um Docker -Images zu konfigurieren, müssen bestimmte Umgebungsvariablen in Ihrer GitHub Actions -Instanz verfügbar sein.
- SNOW_TOKEN: ServiceNow Tokennummer. Es ist eine maskierte Variable und wird nicht in den Aufträgen angezeigt.
- SNOW_TOOLID: ServiceNow Tool-ID.
- SNOW_URL: Instanz-URL ServiceNow.
- CI_PIPELINE_ID: ID der Workflow-Ausführung eines Repositorys. Verwendung – CI_PIPELINE_ID: ${{github.run_id }}
- CI_API_V4_URL: URL des GitHub-Servers. Verwendung – CI_API_V4_URL: ${{ github.server_url }}
- CI_JOB_ID: ID der Workflow-Ausführung eines Repositorys. Verwendung – CI_PIPELINE_ID: ${{github.run_id }}
- CI_PROJECT_PATH: Name des Workflows. Verwendung – CI_PROJECT_PATH: ${{ github.repository }}/${{github.workflow}}
- CI_REPOSITORY_NAME: Name des Repositorys. Verwendung – CI_REPOSITORY_NAME: ${{ github.repository }}
- CI_RUN_ATTEMPT: Anzahl der Workflow-Versuche. Verwendung – CI_RUN_ATTEMPT: ${{ github.run_attempt }}
- CI_PROJECT_TITLE: Name des Workflows. Verwendung – CI_PROJECT_TITLE: ${{ github.repository }}/${{github.workflow}}
- CI_COMMIT_BRANCH: Name der Verzweigung, in der der Workflow ausgeführt wird. Verwendung – CI_COMMIT_BRANCH: ${{ github.ref_name }}
- CI_WORKFLOW_NAME: Name des Workflows. Verwendung – CI_WORKFLOW_NAME: ${{ github.workflow }}
Umgebungsvariablen für Kabelbaum
Zum Konfigurieren von Docker -Images müssen bestimmte Umgebungsvariablen in Ihrer Kabelbaum-Instanz verfügbar sein.
- SNOW_TOKEN: ServiceNow Tokennummer. Es ist eine maskierte Variable und wird nicht in den Aufträgen angezeigt.
- SNOW_TOOLID: ServiceNow Tool-ID.
- SNOW_URL: Instanz-URL ServiceNow.
Die folgenden Umgebungsvariablen müssen in Ihrer Kabelbaum-Pipeline übergeben werden:
-
HARNESS_STAGE_NAME: „<+stage.identifier>“
-
HARNESS_PIPELINE_NAME: "<+org.bezeichner>/<+project.bezeichner>/<+pipeline.name>"
ServiceNow Docker-Image
docker build -t servicenowdocker/sndevops:5.1.0docker push servicenowdocker/sndevops:5.1.0Sie können auch das öffentliche Repository „app-devops-gitlab“ anpassen und ein eigenes Docker-Image zur Übergabe in der Pipeline erstellen.
ServiceNow DevOps Change-Schritt
stages:
- DevOpsChangeApproval
ServiceNow DevOps Change:
stage: DevOpsChangeApproval
image: servicenowdocker/sndevops:5.1.0
script:
- sndevopscli create change -p "{\"changeStepDetails\":{\"timeout\":3600,\"interval\":100},\"attributes\":{\"short_description\":\"Software Deployment\",\"description\":\"Software Deployment.\",\"assignment_group\":\"xxxxxxxxx\",\"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\"}}"
Sie müssen die Eingabewerte für diese anwenderdefinierte Aktion als Zeichenfolge im JSON-Format eingeben.
- changeStepDetails: [optional] Enthält die Zeitüberschreitungs- und Intervalldetails.
- Intervall: [optional] Die Wartezeit in Sekunden zwischen dem Testen der API. Der Standardwert beträgt 100 Sekunden.
- Zeitüberschreitung: [optional] Die maximale Zeit in Sekunden, die gewartet wird, bis die Aktion fehlschlägt. Der Standardwert beträgt 3600 Sekunden.Hinweis:Wenn der Zeitüberschreitungswert auch hier in Ihrem Tool verfügbar ist, wird der frühere Zeitüberschreitungswert berücksichtigt.
- attributes: [optional] Die Attributdetails der Change-Anforderung sind beim Erstellen eines Change in einer Instanz ServiceNow zu verwenden. Die Change-Anforderung ist ein JSON-Objekt, das von geschweiften Klammern {} umgeben ist und Schlüssel-Wert-Paare enthält, die durch ein Komma (,) getrennt sind. Ein Schlüssel-Wert-Paar besteht aus einem Schlüssel und einem Wert, getrennt durch einen Doppelpunkt (:). Die im Schlüssel-Wert-Paar unterstützten Schlüssel sind „short_description“, „description“, „assignment_group“, „implementation_plan“, „backout_plan“, „test_plan“ usw.
- -ctx: [optional] Zusätzliche Kontextparameter im JSON-Format. Umgebungsvariablendetails aus GitHub, die zum Erstellen der Anforderung für die DevOps-Change-API verwendet werden. Beispiel:
sndevopscli create change -ctx "{\"projectId\": \"123456\", \"attemptNumber\": \"${{ github.run_attempt }}\"}" -p "{\"changeStepDetails\": {\"timeout\":3600,\"interval\":100},\"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\"}}" - -w: [optional] Geben Sie an, ob die Pipeline auf die Erstellung und Genehmigung des Change warten soll. Standardmäßig wartet die Pipeline bis zur Erstellung des Change und seiner Genehmigung.
ServiceNow DevOps SonarScan-Ergebnisse
stages:
- DevOpsSonarStage
ServiceNow DevOps SonarScan Results:
stage: DevOpsSonarStage
image: servicenowdocker/sndevops:5.1.0
script:
- sndevopscli create sonar -url 'https://sonarcloud.io' -projectKey 'devsystem2019_TestImportTest'
- url: [Erforderlich] Gibt die Sonar-URL an.
- projectKey: [Erforderlich] Gibt den Sonar-Projektschlüssel an.
- Einschränkung
- Beim Erstellen der Zusammenfassungsergebnisse zur Softwarequalität wird die Umgebungsvariable CI_MERGE_REQUEST_SOURCE_BRANCH_NAME für Zusammenführungspipelines und CI_DEFAULT_BRANCH für Tag-Pipelines verwendet, da die Variable CI_COMMIT_BRANCH nicht für Zusammenführungs- oder Tag-Pipelines verfügbar ist. Weitere Informationen finden Sie in der GitLab-Dokumentation.
Artefakt registrieren
stages:
- artifact
artifact:
stage: artifact
image: servicenowdocker/sndevops:5.1.0
script:
- sndevopscli create artifact -a "[{\"name\":\"Artifact-${CI_JOB_NAME}\",\"repositoryName\":\"Repo\",\"version\":\"1.${CI_JOB_ID}.0\"}]"
Sie müssen die Eingabewerte für diese anwenderdefinierte Aktion als Zeichenfolge im JSON-Format eingeben.
-a: [Erforderlich] Gibt Artefaktdetails an.
Paket registrieren
stages:
- package
package:
stage: package
image: servicenowdocker/sndevops:5.1.0
script:
- sndevopscli create package -n "Package2" -a "[{\"name\":\"Artifact-${CI_JOB_NAME}\",\"repositoryName\":\"Repo\" ,\"version\":\"1.${CI_JOB_ID}.0\"}]"Sie müssen die Eingabewerte für diese anwenderdefinierte Aktion als Zeichenfolge im JSON-Format eingeben.
-n: [Erforderlich] Gibt den Paketnamen an.
Change abrufen
Fügen Sie auf Positionsebene hinzu, um „changeRequestNumber“ aus der Instanz ServiceNow mit den angegebenen „changeDetails“ abzurufen und die Change-Anforderung zu identifizieren.
stages:
- DevOpsGetChange
ServiceNow DevOps Get Change:
stage: DevOpsGetChange
image: servicenowdocker/sndevops:5.1.0
script:
- sndevopscli get change -p "{\"buildNumber\":${CHG_JOB_ID},\"stageName\":\"ServiceNow DevOps Change Step\",\"pipelineName\":\"GitlabDockerGetAndUpdateChange\"}"
-p: It stands for changeDetails. The change details to be used for identifying change request in ServiceNow instance. The change details is a JSON object surrounded by curly braces {} containing key-value pair separated by a comma ,. A key-value pair consists of a key and a value separated by a colon :. The keys supported in key-value pair are buildNumber, pipelineName, stageName
buildNumber: [mandatory]
This specifies ID of the Job where we have created change request.
stageName: [mandatory]
This specifies the Job name where we have created change request..
pipelineName: [mandatory]
This specifies the pipeline name.
Outputs:
sndevopschg.json file created with content: {
"status": "SUCCESS",
"changeRequestNumber": "CHGXXXXX"
}
changeRequestNumber: Change Request Number found for the given change details
status: To know the status of the Change Request GET.
Change aktualisieren
Fügen Sie auf Positionsebene hinzu, um den Change in der Instanz ServiceNow für die changeRequestNumber zu aktualisieren, die als Eingabe zusammen mit changeRequestDetails bereitgestellt wurde.
stages:
- DevOpsUpdateChangeStage
ServiceNow DevOps Update Change:
stage: DevOpsUpdateChangeStage
image: servicenowdocker/sndevops:5.1.0
script:
- 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\"}"
-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.
Precedence of choosing changeRequestNumber:
- changeRequestNumber mentioned in the pipeline yml
- changeRequestNumber stored in sndevopschg.json.
-p : It stands for changeDetails. The change details to be used for Updating the change request information identified by the specified change request number with the key-value pairs. The change details is a JSON object surrounded by curly braces {} containing key-value pair separated by a comma ,. A key-value pair consists of a key and a value separated by a colon :. The keys supported in key-value pair are short_description, state, description, work_notes ..so on
OR
- sndevopscli update change -p "{\"short_description\":\"Updated Automated Software Deployment\",\"description\":\"Automated Software Deployment.\",\"assignment_group\":\"XXXXXXXXXX\",\"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\"}"
NOTE: State should be specified at last in case if you are update the state of change request.
- sndevopscli update change -p "{\"short_description\":\"Updated Automated Software Deployment\",\"description\":\"Automated Software Deployment.\",\"assignment_group\":\"XXXXXXXXXX\",\"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\","state":"3"}'
Change automatisch schließen
Integrieren Sie Changes mit automatischer Schließung in Instanz ServiceNow. Ausführliche Informationen zum automatischen Schließen finden Sie unter Details der Change-Anforderung DevOps innerhalb der Pipeline konfigurieren.
stages:
- changeapproval
ServiceNow DevOps Change Step:
stage: changeapproval
image: servicenowdocker/sndevops:5.1.0
script:
- 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\"}}"
autoCloseChange: [optional] : Boolean value
Sicherheitsscanergebnisse
stages:
- DevOpsSecurityScanStageServiceNow
ServiceNow DevOps Security Scan Results:
stage: DevOpsSecurityScanStageimage
image: servicenowdocker/sndevops:5.1.0
script:
- sndevopscli create securityScan -p "{\"pipelineInfo\":{\"buildNumber\":\"${CI_PIPELINE_ID}\",\"pipelineExecutionUrl\":\"${CI_PIPELINE_URL}\" },\"securityResultAttributes\":{ \"scanner\":\"Veracode\",\"applicationName\":\"PetStoreAPI-Github\",\"buildVersion\":\"\",\"securityToolId\":\"\"}}"
-p: [mandatory]It the payload of security result attributes. The payload will have attributes as follows:
buildNumber: CI_PIPELINE_ID (mandatory)pipelineExecutionUrl: CI_PIPELINE_URL (mandatory)scanner: Scanning tool and is required e.g. Checkmarx One.projectName/projectId: Name/Id of your Checkmarx One project and is required. This attribute is applicable only for Checkmarx One.applicationName: Name of your Veracode application and is required. This attribute is applicable only for Veracode.buildVersion": Veracode Scan name / build version and is optional. This attribute is applicable only for Veracode.scanId: Checkmarx One scan id and is optional. This attribute is applicable only for Checkmarx One.securityToolId: Security tool onboarded in ServiceNow (sys_id of the onboarded security tool) and is optional.
Beispiel für -Pipelines
Beispiel für eine GitLab-Pipeline
image: servicenowdocker/sndevops:5.1.0
stages:
- pre-build
- build
- sonar
- securityscan
- changeapproval
- getchange
- updatechange
- deploy
Pre-Build:
stage: pre-build
script:
- echo $CI_JOB_NAME
Artifact and Package:
stage: build
script:
- sndevopscli create artifact -a "[{\"name\":\"Artifact-${CI_JOB_NAME}\",\"repositoryName\":\"TestRepo\",\"version\":\"1.${CI_RUNNER_ID}.0\"}]"
- sndevopscli create package -n "Test_Package" -a "[{\"name\":\"Artifact-${CI_JOB_NAME}\",\"repositoryName\":\"TestRepo\",\"version\":\"1.${CI_RUNNER_ID}.0\"}]"
ServiceNow DevOps SonarScan Results:
stage: sonar
script:
- sndevopscli create sonar -url 'https://sonarcloud.io' -projectKey 'xxxxxxx'
ServiceNow DevOps Security Scan Results:
stage: securityscan
script:
- 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\":\"\"}}"
ServiceNow DevOps Change Step:
stage: changeapproval
variables:
CHG_JOB_ID: $CI_JOB_ID
script:
- echo "CHG_JOB_ID=$CHG_JOB_ID" >> generated_job_id.env
- 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\":\"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\"}}"
- sndevopscli get change #If we are placing get change cli command in the same job where we are creating change then no need to mention the changeDetails.
artifacts:
paths:
- generated_job_id.env
DevOps Get Change:
stage: getchange
script:
- source generated_job_id.env
- sndevopscli get change -p "{\"buildNumber\":${CHG_JOB_ID},\"stageName\":\"ServiceNow DevOps Change Step\",\"pipelineName\":\"SmrutiTestDemoProject\"}"
artifacts:
paths:
- sndevopschg.json
dependencies:
- ServiceNow DevOps Change Step
DevOps Update Change:
stage: updatechange
script:
#- sndevopscli update change -n 'CHGXXXX' -p "{\"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\"}"
- sndevopscli update change -p "{\"short_description\":\"Updated 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\"}"
dependencies:
- DevOps Get Change
Deploy Job:
stage: deploy
script:
- echo $CI_JOB_NAME
Beispiel für eine GitHub-Aktionspipeline
name: GithubAction
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
permissions:
contents: read
env:
SNOW_URL: ${{ secrets.SNOW_URL }}
SNOW_TOKEN: ${{ secrets.SNOW_TOKEN }}
SNOW_TOOLID: ${{ secrets.SNOW_TOOLID }}
# These are the optional env variables
#CI_PIPELINE_ID: ${{ github.run_id }}
#CI_API_V4_URL: ${{ github.server_url }}
#CI_JOB_ID: ${{ github.run_id }}
#CI_PROJECT_PATH: ${{ github.job }}
#CI_REPOSITORY_NAME: ${{ github.repository }}
#CI_RUN_ATTEMPT: ${{ github.run_attempt }}
#CI_PROJECT_TITLE: ${{ github.repository }}/${{github.workflow}}
#CI_COMMIT_BRANCH: ${{ github.ref_name }}
#CI_WORKFLOW_NAME: ${{ github.workflow }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up JDK 17
run: |
echo 'hello'
ServiceNowDevOpsChange:
runs-on: ubuntu-latest
needs: build
container:
image: servicenowdocker/sndevops:5.1.0
env:
CI_JOB_NAME: "ServiceNowDevOpsChange"
steps:
- name: create change
run: |
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\"}}"
ServiceNowUpdateDevOpsChange:
runs-on: ubuntu-latest
needs: ServiceNowDevOpsChange
container:
image: servicenowdocker/sndevops:5.1.0
env:
CI_JOB_NAME: "ServiceNowDevOpsChange"
steps:
- name: update change
run: |
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\"}"
ArtifactAndPackage:
runs-on: ubuntu-latest
needs: build
container:
image: servicenowdocker/sndevops:5.1.0
env:
CI_JOB_NAME: "ArtifactAndPackage"
steps:
- name: create artifact
run: |
sndevopscli create artifact -a "[{\"name\": \"com:customactiondemo\",\"version\": \"1.${{ github.run_number }}\",\"semanticVersion\": \"1.${{ github.run_number }}.0\",\"repositoryName\": \"${{ github.repository }}\"}]"
sndevopscli create package -n "Test_Package" -a "[{\"name\": \"com:customactiondemo\",\"version\": \"1.${{ github.run_number }}\",\"semanticVersion\": \"1.${{ github.run_number }}.0\",\"repositoryName\": \"${{ github.repository }}\"}]"
ServiceNowDevOpsSonarScanResults:
name: ServiceNowDevOpsSonarScanResults
needs: ArtifactAndPackage
runs-on: ubuntu-latest
container:
image: servicenowdocker/sndevops:5.1.0
env:
CI_JOB_NAME: "ServiceNowDevOpsSonarScanResults"
steps:
- name: devops soanr results
run: |
sndevopscli create sonar -url 'https://sonarcloud.io' -projectKey 'xxxxxxx'
ServiceNowDevOpsSecurityScan:
name: ServiceNowDevOpsSecurityScan
runs-on: ubuntu-latest
needs: build
container:
image: servicenowdocker/sndevops:5.1.0
steps:
- name: security scan
run: |
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\": \"\"}}"
Beispiel für eine Kabelbaum-Pipeline
# This is an example pipeline, and your pipeline and container configurations may vary from the setup shown here.
# Refer to the pipeline stages for Security, Software, and Change configurations.
# Using this YAML file directly will not work as it contains several Harness-specific configurations; check the Command section present for container steps.
pipeline:
name: Example pipeline
identifier: Example_pipeline
projectIdentifier: Example_project
orgIdentifier: ExampleOrg
tags: {}
stages:
- stage:
name: Build
identifier: Build
description: ""
type: Custom
spec:
execution:
steps:
- step:
type: ShellScript
name: ShellScript_1
identifier: ShellScript_1
spec:
shell: Bash
executionTarget: {}
source:
type: Inline
spec:
script: echo "Building.."
environmentVariables: []
outputVariables: []
timeout: 10m
tags: {}
- stage:
name: ServiceNow DevOps Sonar Scan Results
identifier: ServiceNow_DevOps_Sonar_Scan_Results
description: ""
type: Custom
spec:
execution:
steps:
- step:
type: Container
name: Sonar container
identifier: Sonar_container
spec:
connectorRef: docker_connector # harness docker connector
image: servicenowdocker/sndevops:5.1.0
command: |-
export SNOW_URL="<+variable.SNOW_URL>"
export SNOW_TOOLID="<+variable.SNOW_TOOLID>"
export SNOW_TOKEN="<+variable.SNOW_TOKEN>"
export HARNESS_STAGE_NAME="<+stage.identifier>"
export HARNESS_PIPELINE_NAME="<+org.identifier>/<+project.identifier>/<+pipeline.name>"
export CI_COMMIT_BRANCH="main"
sndevopscli create sonar -url 'https://sonarcloud.io' -projectKey 'SONAR_PROJECT_KEY' -branch "main"
shell: Sh
infrastructure:
type: KubernetesDirect
spec:
connectorRef: KUBE_CONNECTOR # harness kubernates connector
namespace: harness-delegate-ng
resources:
limits:
cpu: "0.5"
memory: 500Mi
annotations: {}
labels: {}
containerSecurityContext:
capabilities:
drop: []
add: []
nodeSelector: {}
reports:
type: JUnit
spec:
paths: []
outputVariables: []
envVariables: {}
timeout: 1h
tags: {}
- stage:
name: ServiceNow DevOps Security Scan Results
identifier: ServiceNow_DevOps_Security_Scan_Results
description: ""
type: Custom
spec:
execution:
steps:
- step:
type: Container
name: security
identifier: security
spec:
connectorRef: docker_connector # harness docker connector
image: servicenowdocker/sndevops:5.1.0
command: |-
export SNOW_URL="<+variable.SNOW_URL>"
export SNOW_TOOLID="<+variable.SNOW_TOOLID>"
export SNOW_TOKEN="<+variable.SNOW_TOKEN>"
sndevopscli create securityScan -p \
"{\"pipelineInfo\":{
\"buildNumber\":\"<+stage.nodeExecutionId>\",
\"taskExecutionUrl\":\"<+pipeline.executionUrl>?stage=<+stage.nodeExecutionId>\",
\"orchestrationPipeline\":\"<+org.identifier>/<+project.identifier>/<+pipeline.name>\"
},
\"securityResultAttributes\":{
\"scanner\":\"Veracode\",
\"applicationName\":\"VeraDemo-10\"
}
}"
shell: Sh
infrastructure:
type: KubernetesDirect
spec:
connectorRef: KUBE_CONNECTOR # harness kubernates connector
namespace: harness-delegate-ng
resources:
limits:
cpu: "0.5"
memory: 500Mi
annotations: {}
labels: {}
containerSecurityContext:
capabilities:
drop: []
add: []
nodeSelector: {}
reports:
type: JUnit
spec:
paths: []
outputVariables: []
envVariables: {}
timeout: 1h
tags: {}
- stage:
name: Deploy
identifier: Deploy
description: ""
type: Deployment
spec:
deploymentType: Kubernetes
service:
serviceRef: service
environment:
environmentRef: Dev
deployToAll: false
infrastructureDefinitions:
- identifier: Infra
execution:
steps:
- step:
type: Container
name: ServiceNow change
identifier: ServiceNow_change
spec:
connectorRef: docker_connector # harness docker connector
image: servicenowdocker/sndevops:5.1.0
command: |-
# set mandetory variables. These can be set from Environment variable section of Optional configuration as well.
export HARNESS_STAGE_NAME="<+stage.identifier>"
export SNOW_URL="<+variable.SNOW_URL>"
export SNOW_TOOLID="<+variable.SNOW_TOOLID>"
export SNOW_TOKEN="<+variable.SNOW_TOKEN>"
# "sndevopscli create change" command notifies ServiceNow DevOps to create a change.
# Ensure to update "upstreamStage" accordingly. Example, if you have 3 stages Test, Change and Deploy in your pipeline, then you must update as "upstreamStage": "<+pipeline.stages.Test.nodeExecutionId>". Note that if your change stage is the first stage, you can remove this line.
sndevopscli create change -ctx \
"{
\"pipelineExecutionUrl\":\"<+pipeline.executionUrl>\",
\"stageIdentifier\": \"<+stage.identifier>\",
\"stageNodeExecutionId\": \"<+stage.nodeExecutionId>\",
\"pipelineName\": \"<+pipeline.name>\",
\"upstreamStage\": \"<+pipeline.stages.ServiceNow_DevOps_Security_Scan_Results.nodeExecutionId>\"
}" -p \
"{
\"changeStepDetails\":
{
\"timeout\":3600,
\"interval\":100
},
\"autoCloseChange\":true,
\"attributes\":{
\"chg_model\":\"adffaa9e4370211072b7f6be5bb8f2ed\",
\"short_description\":\"Software Deployment\",
\"description\":\"Automated Software Deployment.\",
\"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\"
}
}"
shell: Sh
infrastructure:
type: KubernetesDirect
spec:
connectorRef: KUBE_CONNECTOR # harness kubernates connector
namespace: harness-delegate-ng
resources:
limits:
cpu: "0.5"
memory: 500Mi
annotations: {}
labels: {}
containerSecurityContext:
capabilities:
drop: []
add: []
nodeSelector: {}
reports:
type: JUnit
spec:
paths: []
outputVariables: []
envVariables: {}
timeout: 1h
- step:
type: ShellScript
name: ShellScript_1
identifier: ShellScript_1
spec:
shell: Bash
executionTarget: {}
source:
type: Inline
spec:
script: echo "Deploying.."
environmentVariables: []
outputVariables: []
timeout: 10m
rollbackSteps: []
tags: {}
failureStrategies:
- onFailure:
errors:
- AllErrors
action:
type: StageRollback
properties:
ci:
codebase:
connectorRef: CI_CONNECTOR
repoName: REPO_NAME
build: <+input>
sparseCheckout: []
notificationRules:
- name: devopsbugbashwp5
identifier: devopsbugbashwp5
pipelineEvents:
- type: AllEvents
notificationMethod:
type: Webhook
spec:
webhookUrl: https://{instance_url}/api/sn_devops/v2/devops/tool/orchestration?toolId={tool sys id}&projectId={project sys id}&ni.nolog.token={token}
enabled: true