ServiceNow ações personalizadas para GitLab
Use as ações personalizadas [ ServiceNow para GitLab para coletar dados relacionados à criação de solicitação de mudança, verificação do Sonar, registro de artefato e registro de pacote em seu pipeline GitLab com a ajuda da imagem do contêiner Docker.
Docker Imagem é um pacote de software que pode ser usado para executar uma aplicação. Esta imagem informa como um contêiner deve ser instanciado e quais componentes de software devem ser executados. Docker O contêiner é um ambiente virtual que combina o código da aplicação e todas as dependências necessárias para executar a aplicação. Para obter mais informações sobre o Docker, consulte a documentação do Docker.
- SNOW_TOKEN: ServiceNow número de token. É uma variável mascarada e não será exibida nos trabalhos.
- SNOW_TOOLID: ServiceNow ID da ferramenta.
- SNOW_URL: ServiceNow URL da instância.
Ao adicionar a variável SNOW_TOKEN, você pode adquirir o token clicando no botão Copiar token no registro da ferramenta, localizado na tabela Ferramenta [sn_devops_tool].
As variáveis de ambiente devem ser atualizadas com os valores disponíveis no pop-up Configurar webhooks manualmente na página de registro da ferramenta. Para obter detalhes sobre como exibir os detalhes da conexão, consulte Configurar webhooks a partir do registro da ferramenta e Configurar webhooks em GitLab manualmente.
ServiceNow Imagem do Docker
docker build -t servicenowdocker/sndevops:4.0.0docker push servicenowdocker/sndevops:4.0.0Você também pode personalizar o repositório público app-devops-gitlab e criar sua própria imagem do Docker para passar no pipeline.
ServiceNow Etapa de mudança do DevOps
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\"}}"
Você deve inserir os valores de entrada para esta ação personalizada como uma cadeia de caracteres no formato JSON.
- changeStepDetails: [opcional] Contém os detalhes do tempo limite e do intervalo.
- intervalo: [opcional] O tempo em segundos de espera entre tentativas da API. O valor padrão é 100 segundos.
- timeout: [opcional] O tempo máximo em segundos de espera até que a ação falhe. O valor padrão é 3600 segundos.Nota:Quando o valor de tempo limite também está disponível aqui no executor de tempo limite no GitLab, o valor de tempo limite que é anterior é considerado.
- atributos: [opcional] Os detalhes do atributo da solicitação de mudança devem ser usados ao criar a mudança na instância ServiceNow. A solicitação de mudança é um objeto JSON entre chaves {} que contém pares de chave-valor separados por uma vírgula (,). Um par de chave-valor consiste em uma chave e um valor separados por dois pontos (:). As chaves compatíveis com o par chave-valor são short_description, description, assign_group, execution_plan, backout_plan, test_plan e assim por diante.
ServiceNow Resultados do SonarScan do DevOps
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: [obrigatório] Especifica a URL do Sonar.
- projectKey: [obrigatório] Especifica a chave do projeto do Sonar.
- Limitação
- Ao criar resultados de resumo de qualidade de software, a variável de ambiente CI_MERGE_REQUEST_SOURCE_BRANCH_NAME será usada para pipelines de mesclagem e CI_DEFAULT_BRANCH será usada para pipelines de marcador porque a variável CI_COMMIT_BRANCH não está disponível para pipelines de mesclagem ou de marcador. Para obter mais informações, consulte a documentação do GitLab.
Registrar artefato
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\"}]"
Você deve inserir os valores de entrada para esta ação personalizada como uma cadeia de caracteres no formato JSON.
-a: [obrigatório] Especifica detalhes do artefato.
Registrar pacote
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\"}]"Você deve inserir os valores de entrada para esta ação personalizada como uma cadeia de caracteres no formato JSON.
-n: [obrigatório] Especifica o nome do pacote.
Obter mudança
Adicione no nível do trabalho para obter changeRequestNumber da instância ServiceNow com os changeDetails fornecidos para identificar a solicitação de mudança.
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.
Atualizar mudança
Adicione no nível de trabalho para atualizar a mudança na instância ServiceNow para o changeRequestNumber fornecido como entrada junto com changeRequestDetails.
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"}'
Fechar mudança automaticamente
Incorpore a mudança de fechamento automático na instância ServiceNow. Para obter informações detalhadas sobre o fechamento automático, consulte Configuração de DevOps detalhes da solicitação de mudança no pipeline.
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