汎用 Docker コンテナイメージを使用したパイプラインのカスタムアクションの実装

  • リリースバージョン: Australia
  • 更新日 2026年03月12日
  • 所要時間:52分
  • ServiceNow のカスタムアクションを使用して、パイプライン内で変更要求の作成、Sonar スキャン、アーティファクト登録、パッケージ登録に関連するデータを、汎用の Docker コンテナイメージを使用して収集します。

    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] テーブルにあるツールレコードの [トークンをコピー] ボタンを選択することで、トークンを取得できます。

    環境変数は、ツールレコードページの [Webhook を手動で構成] ポップアップで使用可能な値で更新する必要があります。接続の詳細を表示する方法の詳細については、「ツールレコードから Webhook を構成」と「Webhook をGitLab で手動で構成」を参照してください。

    GitLab の接続の詳細

    GitHub Actionsの環境変数

    Docker イメージを設定するには、GitHub Actionsインスタンスで特定の環境変数を使用できる必要があります。

    GitHub Actionsインスタンスで次の環境変数を設定する必要があります。
    注:
    変数は、ツールレコードページの [Webhook を手動で構成] ポップアップで使用可能な値で更新する必要があります。
    • SNOW_TOKEN:ServiceNow トークン番号。これはマスクされた変数であり、ジョブには表示されません。
    • SNOW_TOOLID:ServiceNow ツール ID。
    • SNOW_URL:ServiceNow インスタンスの URL。
    注:
    GitHub Actionsに変数を追加する方法については、GitHub のドキュメントを参照してください。
    GitHub アクションパイプラインでは、次の環境変数を渡す必要があります。
    注:
    これらの変数の値は 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 アクションの接続の詳細

    Harness の環境変数

    Docker イメージを設定するには、Harness インスタンスで特定の環境変数を使用できる必要があります。

    次の環境変数は、Harness インスタンスで構成する必要があります。
    注:
    変数は、ツールレコードページの [Webhook を手動で構成] ポップアップで使用可能な値で更新する必要があります。
    • 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>"

    リポジトリを設定すると、リポジトリの環境変数が作成され、最後に設定された変数値が考慮されます。アップグレードのお客様は、既存のリポジトリを再構成するか、インスタンスの環境変数を手動で追加する必要があります。

    Webhook を手動で構成

    ServiceNow Docker イメージ

    パイプラインにカスタムアクションを追加する前に、パイプラインで ServiceNow Docker イメージ (servicenowdocker/sndevops:6.2.0) を渡す必要があります。https://github.com/ServiceNow/app-devops-gitlab にある app-devops-gitlab パブリックリポジトリのクローンを作成し、次のコマンドを実行して Docker イメージを作成できます。
    docker build -t servicenowdocker/sndevops:6.2.0
    docker push servicenowdocker/sndevops:6.2.0
    Docker イメージは、.ymlファイルの先頭に追加できます。ジョブごとに個別に追加する必要はありません。
    注:
    複数のイメージを使用する場合は、ジョブレベルで追加します。

    また、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 Change ステップ

    ServiceNow DevOps 変更カスタムステップをジョブレベルで追加して、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:[オプション] タイムアウトと間隔の詳細を保持します。
    • interval:[オプション] API の試行間隔を秒単位で指定します。デフォルトの値は 100 秒です。
    • timeout:[オプション] アクションが失敗するまで待機する最大時間 (秒)。デフォルトの値は 3600 秒です。
      注:
      ツールでここでタイムアウト値も使用できる場合は、それより前のタイムアウト値が考慮されます。
    • attributes:[オプション] 変更要求属性の詳細は、ServiceNow インスタンスで変更を作成するときに使用されます。変更要求は、カンマ (,) で区切られたキーと値のペアを含む中括弧 {} で囲まれた JSON オブジェクトです。キーと値のペアは、コロン (:)で区切られたキーと値で構成されます。キーと値のペアでサポートされるキーは、short_description、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 Change] キーワードを含める必要があります。
    展開ゲート
    この属性により、 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 Results

    ServiceNow DevOps SonarScan 結果カスタムステップをジョブレベルで追加して、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 Results]) と同じである必要があります。
    制限事項
    ソフトウェア品質サマリー結果の作成中に、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:[必須] パッケージ名を指定します。

    変更の取得

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

    変更の更新

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

    例:
    
    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
    

    セキュリティスキャン結果

    ServiceNow DevOps Security Scan Results カスタムステップをジョブレベルで追加して、セキュリティスキャン結果を取得します。例:
    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 アクションパイプライン

    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\": \"\"}}"
    

    サンプル Harness パイプライン

    # 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] フィールドのデフォルト値を更新することで、両方のカスタムアクションに異なるステップ名を使用できます。