How to use ServiceNow DevOps Change GitHub Action

zackfanning
Tera Contributor

I have most of the pieces in place for a basic GitHub Actions pipeline (build, test, deploy). I have the deploy step under change control so a change gets created, however then it times out and is canceled.

zackfanning_0-1666982017066.png

 

Attempting to use the ServiceNow DevOps Change GitHub Action has been unsuccessful as every time I try to use it I just get this response "Task/Step Execution not created in ServiceNow DevOps for this job/stage Create Change Job. Please check Inbound Events processing details in ServiceNow instance and ServiceNow logs for more details." However I can see the tasks/steps getting created so I'm not sure what the issue is. Here is the code I try to use

  createchange:
    name: Create Change
    needs: test
    environment: Test Env
    runs-on: ubuntu-latest 
    if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
    steps:
      - name: ServiceNow DevOps Change Automation
        uses: ServiceNow/servicenow-devops-change@v1.35.2
        with:
          devops-integration-user-name: ${{ secrets.SN_DEVOPS_USER }}
          devops-integration-user-password: ${{ secrets.SN_DEVOPS_PASSWORD }}
          instance-url: ${{ secrets.SN_INSTANCE_URL_PROD }}
          tool-id: ${{ secrets.SN_ORCHESTRATION_TOOL_ID }}
          context-github: ${{ toJSON(github) }}
          job-name: 'Create Change Job'
          change-request: '{"setCloseCode":"true","attributes":{"short_description":"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; When the change is approved the implementation happens automated by the CICD pipeline within the change planned start and end time window.","backout_plan":"When software fails in production, the previous software release will be re-deployed.","test_plan":"Testing if the software was successfully deployed"}}'          
          interval: '100'
          timeout: '3600'

 

2 REPLIES 2

Daxin1
Tera Contributor

Hi Zack,

The job-name must match the name of the job.

In the code, the name of the job is "Create Change" but the job-name is "Create Change Job" 

So that did fix it but then I noticed 2 Changes being created so I moved the step creating a change into the deploy job and now I get this error 

Error: Internal server error. An unexpected error occurred while processing the request.

Attached the entire pipeline.yml file, not sure what the issue is

name: pipeline
on:
  pull_request:
  push:
    branches:
      - master
#trigger rebuild
jobs:
  build:
    # Purpose of this job is to Apply Remote Changes for the branch triggering 
    # the pipeline build to the Dev instance, then publish the application to 
    # app repo using the template versioning format. 
    name: Publish from Dev
    #environment: Test Env
    runs-on: ubuntu-latest
    # Below line can be used to set conditionals for modifying your pipeline as needed.
    # if: ${{ github.event_name == 'pull_request'}}

    steps:

      - name: ServiceNow CI/CD Apply Changes
        uses: ServiceNow/sncicd-apply-changes@2.0.0
        env:
          nowUsername: ${{ secrets.SN_USERNAME }}
          nowPassword: ${{ secrets.SN_PASSWORD }}
          nowSourceInstance: ${{ secrets.SN_DEV_INSTANCE }}
          appSysID: ${{ secrets.SN_APP_SYSID }}

      - name: ServiceNow CI/CD Publish App
        id: publish_app
        uses: ServiceNow/sncicd-publish-app@2.0.1
        with:
          versionTemplate: 1.1
          versionFormat: template
          # Optional, add +X to version number. Default: 1 
          # incrementBy: X
        env:
          nowUsername: ${{ secrets.SN_USERNAME }}
          nowPassword: ${{ secrets.SN_PASSWORD }}
          nowSourceInstance: ${{ secrets.SN_DEV_INSTANCE }}
          appSysID: ${{ secrets.SN_APP_SYSID }}
          
    # This is required to pass the version number output from Publish App 
    # to the input for Install App in the next job! This is because the jobs 
    # run on different Linux instances, so without this Install App won't know
    # what to install.
    outputs:
      publishversion: ${{ steps.publish_app.outputs.newVersion }}

  test:
    # Purpose of this job is to Install App from the app repo for the version 
    # published in the build job to a Test instance, then run an ATF Test Suite 
    # associated with the app. If Test Suite fails, the app should be Rolled Back 
    # to clean up the persistent Test environment. 
    name: Run ATF in Test
    needs: build
    #environment: Test Env
    runs-on: ubuntu-latest
    # Below line can be used to set conditionals for modifying your pipeline as needed.
    # if: ${{ github.event_name == 'pull_request'}}
    
    steps:
      - name: ServiceNow CI/CD Install App
        id: install_app
        uses: ServiceNow/sncicd-install-app@2.0.0
        with:
          version: ${{ needs.build.outputs.publishversion }}
          # Only applicable if Application Customization is active. 
          # Version of the base application on which to apply the customizations
#          baseAppVersion: '1.2.3'
          # Only applicable if Application Customization is active and the associated 
          # application is a higher version than the currently installed version
          # Default: false
          autoUpgradeBaseApp: false
        env:
          nowUsername: ${{ secrets.SN_USERNAME }}
          nowPassword: ${{ secrets.SN_PASSWORD }}
          nowInstallInstance: ${{ secrets.SN_TEST_INSTANCE }}
          appSysID: ${{ secrets.SN_APP_SYSID }}

      - name: ServiceNow CI/CD Run ATF Test Suite
        uses: ServiceNow/sncicd-tests-run@2.0.0
        with:
          testSuiteSysId: ${{ secrets.SN_ATFTESTSUITE_SYSID }}
        env:
          nowUsername: ${{ secrets.SN_USERNAME }}
          nowPassword: ${{ secrets.SN_PASSWORD }}
          nowInstallInstance: ${{ secrets.SN_TEST_INSTANCE }}

      - name: ServiceNow CI/CD Rollback App
        if: ${{ failure() && steps.install_app.outputs.rollbackVersion }}
        uses: ServiceNow/sncicd-rollback-app@2.0.0
        with:
          version: ${{steps.install_app.outputs.rollbackVersion}}
        env:
          nowUsername: ${{ secrets.SN_USERNAME }}
          nowPassword: ${{ secrets.SN_PASSWORD }}
          nowInstallInstance: ${{ secrets.SN_TEST_INSTANCE }}
          appSysID: ${{ secrets.SN_APP_SYSID }}

    # This is required to pass the version number output from Publish App 
    # to the input for Install App in the next job! This is because the jobs 
    # run on different Linux instances, so without this Install App won't know
    # what to install.
    outputs:
      publishversion: ${{ needs.build.outputs.publishversion }}
      
 # createchange:
 #   name: Create Change
 #   needs: test
 #   environment: Test Env
 #   runs-on: ubuntu-latest 
 #   if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
 #   steps:
 #     - name: Log orchestrationTaskURL
 #       run: echo ${{ format('orchestrationTaskURL:https://github.com{0}/actions/runs/{1}', github.action_repository, github.run_id) }}
      

  deployprod:
    # Purpose of this job is to Install App to a Prod instance. This should only 
    # trigger if the feature branch has been merged to master after a successfully 
    # completed pull request, hence the conditional for push to master. In other words,
    # the first two jobs run on CI, then all three jobs run on CD.
    name: Deploy to Prod
    needs: test
    environment: Test Env
    runs-on: ubuntu-latest
    if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
    steps:
      - name: ServiceNow DevOps Change Automation
        uses: ServiceNow/servicenow-devops-change@v1.35.2
        with:
          devops-integration-user-name: ${{ secrets.SN_DEVOPS_USER }}
          devops-integration-user-password: ${{ secrets.SN_DEVOPS_PASSWORD }}
          instance-url: ${{ secrets.SN_INSTANCE_URL_PROD }}
          tool-id: ${{ secrets.SN_ORCHESTRATION_TOOL_ID }}
          context-github: ${{ toJSON(github) }}
          job-name: 'Deploy to Prod'
          change-request: '{"setCloseCode":"true","attributes":{"short_description":"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; When the change is approved the implementation happens automated by the CICD pipeline within the change planned start and end time window.","backout_plan":"When software fails in production, the previous software release will be re-deployed.","test_plan":"Testing if the software was successfully deployed"}}'          
          interval: '100'
          timeout: '3600'
      - name: ServiceNow CI/CD Install App
        id: install_app_prod
        uses: ServiceNow/sncicd-install-app@2.0.0
        with:
          version: ${{ needs.test.outputs.publishversion }}
          # Only applicable if Application Customization is active. 
          # Version of the base application on which to apply the customizations
#          baseAppVersion: '1.2.3'
          # Only applicable if Application Customization is active and the associated 
          # application is a higher version than the currently installed version
          # Default: false
#          autoUpgradeBaseApp: true
        env:
          nowUsername: ${{ secrets.SN_USERNAME }}
          nowPassword: ${{ secrets.SN_PASSWORD }}
          nowInstallInstance: ${{ secrets.SN_PROD_INSTANCE }}
          appSysID: ${{ secrets.SN_APP_SYSID }}