일반 Docker 컨테이너 이미지를 사용하여 파이프라인에 대한 사용자 지정 작업 구현

  • 릴리스 버전: Australia
  • 업데이트 날짜 2026년 03월 12일
  • 소요 시간: 50분
  • ServiceNow 사용자 지정 작업을 사용하여 일반 Docker 컨테이너 이미지의 도움을 받아 파이프라인에서 변경 요청 생성, Sonar 스캔, 아티팩트 등록 및 패키지 등록과 관련된 데이터를 수집합니다.

    Docker 이미지는 애플리케이션을 실행하는 데 사용할 수 있는 소프트웨어 패키지입니다. 이 이미지는 컨테이너를 인스턴스화하는 방법과 실행해야 하는 소프트웨어 구성요소를 알려줍니다. Docker 컨테이너는 애플리케이션 코드와 애플리케이션을 실행하는 데 필요한 모든 의존성을 결합하는 가상 환경입니다. Docker에 대한 자세한 내용은 Docker 설명서를 참조하세요.

    GitLab에 대한 환경 변수

    이미지를 구성 Docker 하려면 프로젝트의 인스턴스에서 GitLab 다음 환경 변수를 사용할 수 있어야 합니다.
    • SNOW_TOKEN: ServiceNow 토큰 번호입니다. 마스킹된 변수이며 작업에 표시되지 않습니다.
    • SNOW_TOOLID: ServiceNow 도구 ID.
    • SNOW_URL: ServiceNow 인스턴스 URL
    프로젝트를 구성 GitLab 하면 프로젝트에 대한 환경 변수가 생성되고 최근에 구성된 변수 값이 고려됩니다. 업그레이드하는 고객인 경우 기존 GitLab 프로젝트를 재구성하거나 인스턴스에 GitLab 환경 변수를 수동으로 추가해야 합니다. 변수 추가에 대한 자세한 내용은 GitLab 설명서를 참조하십시오.

    SNOW_TOKEN 변수를 추가할 때 도구 [sn_devops_tool] 테이블에 있는 도구 기록에서 토큰 복사 버튼을 선택하여 토큰을 획득할 수 있습니다.

    환경 변수는 도구 기록 페이지의 수동으로 웹후크 구성 팝업에서 사용할 수 있는 값으로 업데이트해야 합니다. 연결 상세 정보를 보는 방법에 대한 자세한 내용은 해당 문서를 참조하십시오 도구 기록에서 웹후크 구성에서 수동으로 웹후크 GitLab 구성.

    GitLab에 대한 연결 상세 정보

    GitHub Actions에 대한 환경 변수

    이미지를 구성 Docker 하려면 인스턴스에서 GitHub Actions 특정 환경 변수를 사용할 수 있어야 합니다.

    인스턴스에서 GitHub Actions 다음 환경 변수를 구성해야 합니다.
    주:
    도구 기록 페이지의 수동으로 웹후크 구성 팝업에서 사용할 수 있는 값으로 변수를 업데이트해야 합니다.
    • SNOW_TOKEN: ServiceNow 토큰 번호입니다. 마스킹된 변수이며 작업에 표시되지 않습니다.
    • SNOW_TOOLID: ServiceNow 도구 ID.
    • SNOW_URL: ServiceNow 인스턴스 URL
    주:
    에서 변수를 GitHub Actions추가하는 방법에 대한 자세한 내용은 GitHub 설명서를 참조하십시오.
    다음 환경 변수를 GitHub Actions 파이프라인에 전달해야 합니다.
    주:
    이러한 변수의 값은 GitHub에서 동적으로 검색되며 별도로 구성할 필요가 없습니다.
    • PIPELINE_ID: 리포지토리의 워크플로우 실행 ID입니다. 사용량 - PIPELINE_ID: ${{github.run_id }}
    • API_V4_URL: GitHub 서버의 URL. 사용량 - API_V4_URL: ${{ github.server_url }}
    • JOB_ID: 리포지토리의 워크플로우 실행 ID입니다. 사용량 - PIPELINE_ID: ${{github.run_id }}
    • PROJECT_PATH: 워크플로우의 이름입니다. 사용법 - PROJECT_PATH: ${{ github.repository }}/${{github.workflow}}
    • REPOSITORY_NAME: 리포지토리의 이름입니다. 사용량 - REPOSITORY_NAME: ${{ github.repository }}
    • RUN_ATTEMPT: 워크플로우 시도 횟수입니다. 사용량 - RUN_ATTEMPT: ${{ github.run_attempt }}
    • PROJECT_TITLE: 워크플로우의 이름입니다. 사용법 - PROJECT_TITLE: ${{ github.repository }}/${{github.workflow}}
    • COMMIT_BRANCH: 워크플로우가 실행되는 분기의 이름입니다. 사용량 - COMMIT_BRANCH: ${{ github.ref_name }}
    • WORKFLOW_NAME: 워크플로우의 이름입니다. 사용량 - WORKFLOW_NAME: ${{ github.workflow }}
    리포지토리를 구성하면 리포지토리에 대한 환경 변수가 만들어지고 최근에 구성된 변수 값이 고려됩니다. 업그레이드하는 고객이라면 기존 리포지토리를 다시 구성하거나 인스턴스에 환경 변수를 수동으로 추가해야 합니다.

    GitHub 작업에 대한 연결 상세 정보

    하네스에 대한 환경 변수

    이미지를 구성 Docker 하려면 Harness 인스턴스에서 특정 환경 변수를 사용할 수 있어야 합니다.

    Harness 인스턴스에서 다음 환경 변수를 구성해야 합니다.
    주:
    도구 기록 페이지의 수동으로 웹후크 구성 팝업에서 사용할 수 있는 값으로 변수를 업데이트해야 합니다.
    • SNOW_TOKEN: ServiceNow 토큰 번호입니다. 마스킹된 변수이며 작업에 표시되지 않습니다.
    • SNOW_TOOLID: ServiceNow 도구 ID.
    • SNOW_URL: ServiceNow 인스턴스 URL

    다음 환경 변수를 Harness 파이프라인에 전달해야 합니다.

    • HARNESS_STAGE_NAME: "<+stage.identifier>"

    • HARNESS_PIPELINE_NAME: "<+org.identifier>/<+project.identifier>/<+pipeline.name>"

    리포지토리를 구성하면 리포지토리에 대한 환경 변수가 만들어지고 최근에 구성된 변수 값이 고려됩니다. 업그레이드하는 고객이라면 기존 리포지토리를 다시 구성하거나 인스턴스에 환경 변수를 수동으로 추가해야 합니다.

    수동으로 웹후크 구성 화면

    ServiceNow Docker 이미지

    파이프라인에 사용자 지정 작업을 추가하기 전에 파이프라인에서 Docker 이미지(servicenowdocker/sndevops:6.2.0)를 전달 ServiceNow 해야 합니다. 에 있는 https://github.com/ServiceNow/app-devops-gitlabapp-devops-gitlab 공개 리포지토리를 복제하고 다음 명령을 실행하여 Docker 이미지를 생성할 수 있습니다.
    docker build -t servicenowdocker/sndevops:6.2.0
    docker push servicenowdocker/sndevops:6.2.0
    .yml 파일의 시작 부분에 Docker 이미지를 추가할 수 있습니다. 각 작업에 개별적으로 추가할 필요는 없습니다.
    주:
    여러 이미지를 사용하려면 작업 수준에서 추가합니다.

    app-devops-gitlab 공개 리포지토리를 사용자 지정하고 파이프라인에 전달할 고유한 Docker 이미지를 생성할 수도 있습니다.

    프록시 구성

    인스턴스가 GitLab 프록시 서버 뒤에서 실행되거나 프록시를 통해 요청을 라우팅하려면 배포에서 환경 변수를 사용하여 프록시 설정을 구성해야 합니다 Docker .

    프록시 지원을 위해 다음 환경 변수를 구성합니다.
    • PROXY_ENDPOINT: #(예: http://localhost:7080 또는 https://proxy.example.com:8080
    • PROXY_USERNAME: # 선택 사항: 프록시 인증용
    • PROXY_PASSWORD: # 선택 사항: 프록시 인증용
    • PROXY_AUTH: # 선택 사항: API 키를 사용한 대체 인증
    PROXY_ENDPOINT HTTP 또는 HTTPS일 수 있습니다. 이전 버전과의 호환성을 위해 HTTP_PROXY 및 HTTPS_PROXY도 지원됩니다. HTTPS 프록시와 함께 자체 서명된 인증서를 사용하는 경우 NODE_TLS_REJECT_UNAUTHORIZED=0(테스트 전용)을 설정합니다. 인증은 다음 방법을 통해 제공할 수 있습니다.
    • 사용자 이름/암호: PROXY_USERNAME 및 PROXY_PASSWORD 사용
    • API 키: PROXY_AUTH 사용
    • 인증 없음: 인증 변수를 설정하지 않은 상태로 둡니다.
    예:
    stages:
      - package
    
    package:
      stage: package
      image: servicenowdocker/sndevops:6.2.0
      variables:
        PROXY_ENDPOINT: "https://proxy.example.com:8080"
        PROXY_USERNAME: "proxy_user"
        PROXY_PASSWORD: "proxy_pass"
      script: 
        - sndevopscli create package -n "package-name" -a '[{"name":"artifact-name","repositoryName":"artifact-repo-name","version":"1.3.0"}]'

    ServiceNow DevOps 변경 단계

    작업 수준에서 DevOps 변경 사용자 지정 단계를 추가 ServiceNow 하여 인스턴스에 ServiceNow 변경을 생성합니다. 예:
    
    stages:
      - DevOpsChangeApproval
    
    ServiceNow DevOps Change:
      stage: DevOpsChangeApproval
      image: servicenowdocker/sndevops:6.2.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\"}}"
    
    
    주:
    Docker 변경 단계와 when: 수동 지침 변경 단계를 모두 사용하는 경우 다른 작업 수준에서 추가해야 합니다.

    이 사용자 지정 작업에 대한 입력 값을 JSON 형식의 문자열로 입력해야 합니다.

    • changeStepDetails: [선택 사항] 시간 제한 및 간격 상세 정보가 포함되어 있습니다.
    • 간격: [선택 사항] API를 시도하는 사이에 대기하는 시간(초)입니다. 기본값은 100초입니다.
    • timeout: [선택 사항] 작업이 실패할 때까지 기다리는 최대 시간(초)입니다. 기본값은 3600초입니다.
      주:
      여기 도구에서도 시간 제한 값을 사용할 수 있는 경우 이전의 시간 제한 값이 고려됩니다.
    • 속성: [옵션] 변경 요청 속성 상세 정보는 인스턴스에서 ServiceNow 변경을 생성하는 동안 사용됩니다. 변경 요청은 쉼표(,)로 구분된 키-값 쌍을 포함하는 중괄호 {}로 둘러싸인 JSON 객체입니다. 키-값 쌍은 콜론(:)으로 구분된 키와 값으로 구성됩니다. 키-값 쌍에서 지원되는 키는 short_description, 설명, assignment_group, implementation_plan, backout_plan, test_plan 등입니다.
    • -ctx: [선택 사항] JSON 형식의 추가 컨텍스트 매개변수입니다. DevOps 변경 API에 대한 요청을 빌드하는 데 사용할 GitHub의 환경 변수 상세 정보입니다. 예:
      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: [선택 사항] 파이프라인이 변경 생성 및 승인을 기다려야 하는지 여부를 지정합니다. 기본적으로 파이프라인은 변경 생성 및 승인이 이루어질 때까지 대기합니다.
    주:
    변경 단계의 이름에는 작업 이름인 ServiceNow DevOps 변경 키워드가 포함되어야 합니다.
    배포 게이트
    이 속성을 사용하면 sndevopscli를 사용하여 변경 요청을 생성하는 동안 데이터를 전달할 수 있으며 동시에 와 같은 GitLab도구에서 제공하는 수동 작업 기능을 사용합니다. 예:
    stages:
      - DevOpsChangeApproval
      - deploy
    
    ServiceNow DevOps Change:
      stage: DevOpsChangeApproval
      image: servicenowdocker/sndevops:6.2.0
      script: 
        - sndevopscli create change -p '{"changeStepDetails":{"timeout":3600,"interval":100},"deploymentGateDetails":{"jobName":"sn-change-job"},"attributes":{"short_description":"Automated 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"}}'
    
    sn-change-job:
      stage: deploy
      needs:
        job: ServiceNow DevOps Change
      when: manual
      allow_failure: false
      script: |
        echo sn-change-job

    선택적 deploymentGateDetails 속성에는 파이프라인의 다운스트림 수동 작업 이름을 보유하는 jobName 속성이 포함되어야 합니다.

    ServiceNow DevOps SonarScan 결과

    작업 수준에서 DevOps SonarScan 결과 사용자 지정 단계를 추가 ServiceNow 하여 인스턴스에 ServiceNow Sonar 요약을 생성합니다. 예:
    
    stages:
      - DevOpsSonarStage
    
    ServiceNow DevOps SonarScan Results:
      stage: DevOpsSonarStage
      image: servicenowdocker/sndevops:6.2.0
      script: 
        - sndevopscli create sonar -url 'https://sonarcloud.io' -projectKey 'devsystem2019_TestImportTest'
    
    
    • url: [필수] Sonar URL을 지정합니다.
    • projectKey: [필수] Sonar 프로젝트 키를 지정합니다.
    주:
    Sonar 단계의 이름은 작업 이름( ServiceNow DevOps SonarScan 결과)과 같아야 합니다.
    제한사항
    소프트웨어 품질 요약 결과를 생성하는 동안 MERGE_REQUEST_SOURCE_BRANCH_NAME 환경 변수는 병합 파이프라인에 사용되며, COMMIT_BRANCH 변수는 병합 또는 태그 파이프라인에 사용할 수 없기 때문에 DEFAULT_BRANCH 태그 파이프라인에 사용됩니다. 자세한 내용은 GitLab 설명서를 참조하십시오.

    아티팩트 등록

    작업 수준에서 아티팩트 사용자 지정 단계를 추가하여 인스턴스에 ServiceNow 아티팩트를 등록합니다. 예:
    
    stages:
      - artifact
    
    artifact:
      stage: artifact
      image: servicenowdocker/sndevops:6.2.0
      script: 
        - sndevopscli create artifact -a "[{\"name\":\"Artifact-${JOB_NAME}\",\"repositoryName\":\"Repo\",\"version\":\"1.${JOB_ID}.0\"}]"
     

    이 사용자 지정 작업에 대한 입력 값을 JSON 형식의 문자열로 입력해야 합니다.

    -a: [필수] 이 값은 아티팩트 상세 정보를 지정합니다.

    패키지 등록

    작업 수준에서 패키지 사용자 지정 단계를 추가하여 인스턴스에 ServiceNow 패키지를 등록합니다. 예:
    
    stages:
      - package
    
    package:
      stage: package
      image: servicenowdocker/sndevops:6.2.0
      script: 
        - sndevopscli create package -n "Package2" -a "[{\"name\":\"Artifact-${JOB_NAME}\",\"repositoryName\":\"Repo\" ,\"version\":\"1.${JOB_ID}.0\"}]"

    이 사용자 지정 작업에 대한 입력 값을 JSON 형식의 문자열로 입력해야 합니다.

    -n: [필수] 패키지 이름을 지정합니다.

    변경 사항 가져오기

    변경 요청을 식별하기 위해 지정된 changeDetails가 있는 인스턴스에서 ServiceNow changeRequestNumber를 가져오려면 작업 수준에서 추가합니다.

    예:
    
    
    stages:
      - DevOpsGetChange
    
    ServiceNow DevOps Get Change:
      stage: DevOpsGetChange
      image: servicenowdocker/sndevops:6.2.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.
    

    변경 업데이트

    작업 수준에서 추가하여 changeRequestDetails와 함께 입력으로 제공된 changeRequestNumber에 대한 인스턴스의 ServiceNow 변경을 업데이트합니다.

    예:
    
    stages:
      - DevOpsUpdateChangeStage
    
    ServiceNow DevOps Update Change:
      stage: DevOpsUpdateChangeStage
      image: servicenowdocker/sndevops:6.2.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"}'
    

    변경 자동 종결

    인스턴스에 자동 종결 변경을 통합합니다 ServiceNow . 자동 종결에 대한 자세한 내용은 다음 문서를 참조하십시오 파이프라인 내에서 변경 요청 상세 정보 구성 DevOps.

    예:
    
    stages:
      - changeapproval
    
    ServiceNow DevOps Change Step:
      stage: changeapproval
      image: servicenowdocker/sndevops:6.2.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
    

    보안 스캔 결과

    작업 수준에서 DevOps 보안 검사 결과 사용자 지정 단계를 추가 ServiceNow 하여 보안 검사 결과를 검색합니다. 예:
    stages:
      - DevOpsSecurityScanStageServiceNow 
    
    ServiceNow DevOps Security Scan Results:
      stage: DevOpsSecurityScanStageimage 
      image: servicenowdocker/sndevops:6.2.0
      script: 
          - sndevopscli create securityScan -p "{\"pipelineInfo\":{\"buildNumber\":\"${PIPELINE_ID}\",\"pipelineExecutionUrl\":\"${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: PIPELINE_ID (mandatory)pipelineExecutionUrl: 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.
     

    샘플 파이프라인

    샘플 GitLab 파이프라인

    
    image: servicenowdocker/sndevops:6.2.0
    stages:
      - pre-build
      - build
      - sonar
      - securityscan
      - changeapproval
      - getchange
      - updatechange
      - deploy
    
    
    Pre-Build:
      stage: pre-build
      script:
        - echo $JOB_NAME
        
    Artifact and Package:
      stage: build
      script:
        - sndevopscli create artifact -a "[{\"name\":\"Artifact-${JOB_NAME}\",\"repositoryName\":\"TestRepo\",\"version\":\"1.${RUNNER_ID}.0\"}]"
        - sndevopscli create package -n "Test_Package" -a "[{\"name\":\"Artifact-${JOB_NAME}\",\"repositoryName\":\"TestRepo\",\"version\":\"1.${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\":\"${JOB_ID}\", \"stageName\":\"ServiceNow DevOps Security Scan Results\",\"taskExecutionUrl\":\"${JOB_URL}\" },\"securityResultAttributes\":{ \"scanner\":\"Veracode\",\"applicationName\":\"PetStoreAPI-Github\",\"buildVersion\":\"\",\"securityToolId\":\"\"}}"
    
    ServiceNow DevOps Change Step:
      stage: changeapproval
      variables:
        CHG_JOB_ID: $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 $JOB_NAME

    샘플 GitHub Actions 파이프라인

    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
      #PIPELINE_ID: ${{ github.run_id }}
      #API_V4_URL: ${{ github.server_url }}
      #JOB_ID: ${{ github.run_id }}
      #PROJECT_PATH: ${{ github.job }}
      #REPOSITORY_NAME: ${{ github.repository }}
      #RUN_ATTEMPT: ${{ github.run_attempt }}
      #PROJECT_TITLE: ${{ github.repository }}/${{github.workflow}}
      #COMMIT_BRANCH: ${{ github.ref_name }}
      #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:6.2.0
         env:
           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:6.2.0
           env:
             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:6.2.0
          env:
            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:6.2.0
          env:
            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:6.2.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\": \"\"}}"
    

    샘플 하네스 파이프라인

    # 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:6.2.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 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:6.2.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:6.2.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: 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
    주:
    Sonar 스캔 결과와 보안 스캔 결과를 동일한 스테이지에 추가하려면 sn_devops_tool_integration_configuration 테이블의 sonar_step_names 필드와 security_step_names 필드에서 기본값을 업데이트하여 사용자 지정 작업 모두에 대해 서로 다른 단계 이름을 사용할 수 있습니다.