---
sourceDocument: Xanadu IT Service Management
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/xanadu/it-service-management

 Release :

    - xanadu

ft:locale :

    - ja-JP

ft:publication_title :

    - Xanadu IT Service Management

ft:clusterId :

    - itsm

bundleId :

    - itsm

workflow :

    - Technology


---

# ServiceNow のカスタムアクション GitLab

# ServiceNow のカスタムアクション GitLab {#ariaid-title1}

* リリースバージョン: Xanadu
* 
* 更新日 2024年08月01日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：16分

GitLab 用の ServiceNow カスタムアクションを使用して、コンテナーイメージを使用して、GitLabパイプラインでの変更要求の作成、Sonar スキャン、アーティファクト登録、およびパッケージ登録に関連するデータを収集しDocker。

Docker イメージは、アプリケーションの実行に使用できるソフトウェアパッケージです。このイメージは、コンテナーをインスタンス化する方法と、どのソフトウェア コンポーネントを実行する必要があるかを示します。Docker コンテナーは、アプリケーションコードと、アプリケーションの実行に必要なすべての依存関係を組み合わせた仮想環境です。Docker の詳細については、 [Docker のドキュメント](https://docs.docker.com/get-started/overview/)を参照してください。  
Docker イメージを構成するには、プロジェクトの GitLab インスタンスで次の環境変数が使用可能である必要があります。

* SNOW_TOKEN: ServiceNow トークン番号。これはマスクされた変数であり、ジョブには表示されません。
* SNOW_TOOLID: ServiceNow ツール ID。
* SNOW_URL: ServiceNow インスタンスの URL。

{#servicenow-custom-actions-for-gitlab__ul_nvc_2z5_yzb}GitLabプロジェクトを構成すると、プロジェクトの環境変数が作成され、最後に構成された変数値が考慮されます。アップグレードのお客様は、既存の GitLab プロジェクトを再構成するか、 GitLab インスタンスに環境変数を手動で追加する必要があります。変数の追加については、 [GitLab のドキュメント](https://docs.gitlab.com/ee/ci/variables/)を参照してください。

SNOW_TOKEN変数を追加するときに、ツール \[sn_devops_tool\] テーブルにあるツール レコードの \[ トークンをコピー \] ボタンをクリックしてトークンを取得できます。

環境変数は、ツールレコードページの \[Webhook を手動で構成 (Configure Webhooks manually)\] ポップアップで使用可能な値で更新する必要があります。接続の詳細を表示する方法の詳細については、「 [ツールレコードから Webhook を構成](https://servicenow-prod.fluidtopics.net/47~cUH0P4BLJ29wyMLQZAw "ツールレコードから Webhook を構成して、ツールが接続された後に DevOps チェンジベロシティ にデータを送信します。") と [GitLab での Webhook の手動構成](https://servicenow-prod.fluidtopics.net/UvfoBgSShdxHcG9o50nKxw "ジョブ通知とプッシュ通知を DevOps アプリケーションに送信するには、GitLab で Webhook を手動で構成します。")」を参照してください。

## ServiceNow Docker イメージ {#servicenow-custom-actions-for-gitlab__section_tys_cbd_zzb}

パイプラインにカスタムアクションを追加する前に、パイプラインで 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

Docker イメージは、.ymlファイルの先頭に追加できます。ジョブごとに個別に追加する必要はありません。  
注:  
複数のイメージを使用する場合は、ジョブレベルで追加します。

また、app-devops-gitlab パブリックリポジトリをカスタマイズし、独自の Docker イメージを作成してパイプラインに渡すこともできます。

## ServiceNow DevOps 変更ステップ {#servicenow-custom-actions-for-gitlab__section_w34_zw5_yzb}

\[ 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 変更ステップと when: 手動指示変更ステップの両方を使用している場合は、必ず異なるジョブ・レベルで追加してください。

このカスタムアクションの入力値は、JSON 形式の文字列として入力する必要があります。  
* changeStepDetails: \[オプション\] タイムアウトと間隔の詳細を保持します。
* interval: \[オプション\] API の試行間隔を秒単位で指定します。デフォルト値は 100 秒です。
* timeout: \[オプション\] アクションが失敗するまで待機する最大時間 (秒)。デフォルト値は 3600 秒です。  
  注:  
  GitLab の Timeout runner でもタイムアウト値が使用可能な場合は、早い方のタイムアウト値が考慮されます。
* attributes: \[オプション\] 変更要求属性の詳細は、 ServiceNow インスタンスで変更を作成するときに使用されます。変更要求は、カンマ (,) で区切られたキーと値のペアを含む中括弧 {} で囲まれた JSON オブジェクトです。キーと値のペアは、コロン (:)で区切られたキーと値で構成されます。キーと値のペアでサポートされるキーは、short_description、説明、assignment_group、implementation_plan、backout_plan、test_plan などです。

{#servicenow-custom-actions-for-gitlab__ul_szf_4bd_zzb}  
注:  
変更ステップの名前には、ジョブ名である ServiceNow DevOps Change キーワードを含める必要があります。

## ServiceNow DevOps SonarScan の結果 {#servicenow-custom-actions-for-gitlab__section_osj_zw5_yzb}

ServiceNow DevOps SonerScan 結果カスタムステップをジョブレベルで追加して、ServiceNow インスタンスに Sonar サマリーを作成します。例：


    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-custom-actions-for-gitlab__ul_nrg_hbd_zzb}  
注:  
Sonar ステップの名前は、ジョブ名 ( 「ServiceNow DevOps SonarScan Results」) と同じである必要があります。  

制限事項
:   ソフトウェア品質サマリー結果の作成中、CI_MERGE_REQUEST_SOURCE_BRANCH_NAME環境変数は結合パイプラインに使用され、CI_COMMIT_BRANCH変数は結合パイプラインまたはタグパイプラインでは使用できないため、CI_DEFAULT_BRANCH 環境変数はタグパイプラインに使用されます。詳細については、 [GitLab のドキュメント](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html)を参照してください。

## アーティファクトを登録 {#servicenow-custom-actions-for-gitlab__section_dmt_zw5_yzb}

アーティファクトカスタムステップをジョブレベルで追加して、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-custom-actions-for-gitlab__section_jnc_tx5_yzb}

パッケージカスタムステップをジョブレベルで追加して、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: \[必須\] パッケージ名を指定します。

## 変更を取得 {#servicenow-custom-actions-for-gitlab__section_h34_tyw_v1c}

ジョブレベルで追加し ServiceNow 指定された changeDetails を持つインスタンスから 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.

## 変更の更新 {#servicenow-custom-actions-for-gitlab__section_efb_lyw_v1c}

ジョブレベルで追加して ServiceNow changeRequestDetails とともに入力として指定された changeRequestNumber のインスタンスの変更を更新します。  
例：


    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-custom-actions-for-gitlab__section_adl_hzw_v1c}

ServiceNowインスタンスに自動クローズ変更を組み込みます。自動終了の詳細については、「 [パイプライン内で DevOps 変更要求の詳細を構成する](https://servicenow-prod.fluidtopics.net/~k56n2JpbhUneOCLEUkJRw "パイプラインの変更ステップで、パイプライン内からクローズ情報、変更ステータス、および変更要求フィールドを更新する方法を構成します。")」を参照してください。  
例：


    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


