ServiceNow 에 대한 사용자 지정 작업 GitLab

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

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

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

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

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

    연결 세부 정보.

    ServiceNow Docker 이미지

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

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

    ServiceNow DevOps 변경 단계

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

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

    • changeStepDetails: [선택 사항] 시간 제한 및 간격 세부 정보를 보유합니다.
    • interval: [선택 사항] API 시도 사이에 대기하는 시간(초)입니다. 기본값은 100초입니다.
    • timeout: [선택 사항] 작업이 실패할 때까지 대기하는 최대 시간(초)입니다. 기본값은 3600초입니다.
      주:
      GitLab의 Timeout 러너에서도 시간 제한 값을 사용할 수 있는 경우 이전 시간 제한 값이 고려됩니다.
    • 속성: [선택 사항] 변경 요청 속성 상세 정보는 인스턴스에서 ServiceNow 변경을 생성하는 동안 사용됩니다. 변경 요청은 쉼표(,)로 구분된 키-값 쌍을 포함하는 중괄호 {}로 둘러싸인 JSON 객체입니다. 키-값 쌍은 콜론(:)으로 구분된 키와 값으로 구성됩니다. 키-값 페어에서 지원되는 키는 short_description, 설명, assignment_group, implementation_plan, backout_plan, test_plan 등입니다.
    주:
    변경 단계의 이름에는 작업 이름인 ServiceNow DevOps 변경 키워드가 포함되어야 합니다.

    ServiceNow DevOps SonarScan 결과

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

    아티팩트 등록

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

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

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

    패키지 등록

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

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

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

    변경 사항 가져오기

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

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