Sign inSign up

dynatraceace/keptn-gitlab-runner

By dynatraceace

Updated over 3 years ago

For source: https://gitlab.com/dynatrace-ace/keptn-gitlab-runner

Image
0

4.6K

dynatraceace/keptn-gitlab-runner repository overview

Deprecation notice

This repository has been deprecated. Dynatrace Cloud Automation as well as Keptn Quality Gate CI/CD integrations were combined in the new cloud-automation-tools repository.


Keptn GitLab Runner

Container image containing logic to integrate quality gates usecases with your GitLab CI Pipelines

AuthorContainer Image TagKeptn Supported VersionComment
@kristofre1.00.7.xInitial Release
@kristofre2.00.8.3Support for Keptn 0.8.3
@tobigremmer-dt2.10.8.3Support for environment variables containing custom timezones

Stages

Note: there is a full sample pipeline in the samples directory

Keptn Init

Keptn needs to be initialized (project, stage, service, SLOs, SLIs, monitoring, ...) to inform Keptn about what is going to be evaluated.

You can add the stage to the .gitlab-ci.yaml file:

prepare_keptn:
  image: dynatraceace/keptn-gitlab-runner:latest
  stage: init
  environment:
    name: test
  variables: 
    KEPTN_PROJECT: simplenode-gitlab
    KEPTN_SERVICE: simplenodeservice
    KEPTN_STAGE: staging
    KEPTN_SOURCE: gitlab
    KEPTN_MONITORING: dynatrace
  script:
    - /keptn/keptn_init.sh
  artifacts:
    paths: 
    - keptn.init.json

The following variables can be set, either on the job, pipeline or global level:

VariableDescriptionRequiredDefault
KEPTN_ENDPOINTThe endpoint URL of Keptn. e.g.: https://keptn.domain.comyes
KEPTN_API_TOKENThe API token to authenticate with the Keptn API. Suggest to set this as a secret.yes
KEPTN_PROJECTThe name of the Keptn project. e.g.: helloprojectyes
KEPTN_SERVICEThe name of the Keptn service. e.g.: helloserviceyes
KEPTN_STAGEThe name of the Keptn stage. e.g.: stagingyes
KEPTN_MONITORINGThe solution used for monitoringnodynatrace
SHIPYARD_FILEThe path location of the shipyard filenokeptn/shipyard.yaml
SLO_FILEThe path location of the SLO filenokeptn/slo.yaml
SLI_FILEThe path location of the SLI filenokeptn/sli.yaml
DT_CONFIG_FILEThe path location of the Dynatrace conf filenokeptn/dynatrace.conf.yaml
KEPTN_DEBUGDebug outputno0

Note: During Keptn init, a file called keptn.init.${CI_PIPELINE_IID}.json gets created that contains the following data and that can be reused in future stages:

  • KEPTN_PROJECT
  • KEPTN_SERVICE
  • KEPTN_STAGE
  • KEPTN_ENDPOINT
  • KEPTN_BRIDGE_ENDPOINT
Keptn Eval

Once the tests have been run, this job needs to execute to evaluate the SLOs that were defined.

You can add the stage to the .gitlab-ci.yaml file:

quality_gate:
  image: dynatraceace/keptn-gitlab-runner:latest
  stage: eval
  environment:
    name: test
  variables: 
    KEPTN_LABELS: '[{"label1":"foo"},{"label2":"bar"}]'
  script:
    - /keptn/keptn_eval.sh

The following variables can be set, either on the job, pipeline or global level:

VariableDescriptionRequiredDefault
KEPTN_ENDPOINTThe endpoint URL of Keptn. e.g.: https://keptn.domain.com. This would normally already be set in the keptn_init jobyes
KEPTN_API_TOKENThe API token to authenticate with the Keptn API. Suggest to set this as a secret. This would normally already be set in the keptn_init jobyes
KEPTN_PROJECTThe name of the Keptn project. e.g.: helloprojectyesread from keptn.init.${CI_PIPELINE_IID}.json
KEPTN_SERVICEThe name of the Keptn service. e.g.: helloserviceyesread from keptn.init.${CI_PIPELINE_IID}.json
KEPTN_STAGEThe name of the Keptn stage. e.g.: stagingyesread from keptn.init.${CI_PIPELINE_IID}.json
KEPTN_EVAL_MODEHow to define the start and end time of the evaluation. Can be one of the following: from_file or custom_range. See section below on setting timestampsnofrom_file
KEPTN_EVAL_STARTWhen using custom_range for KEPTN_EVAL_MODE, the start time of the evaluation. See section below on setting timestampsno
KEPTN_EVAL_ENDWhen using custom_range for KEPTN_EVAL_MODE, the end time of the evaluation. See section below on setting timestampsno
STOP_ON_FAILUREBoolean value dictating if the pipeline should fail based on evaluationno1
KEPTN_LABELSAdditional labels that are sent to Keptn when evaluation. They need to be set in the following format: '[{"someLabel":"foo"},{"anotherLabel":"bar"}]'no
Setting time stamps for evaluation

Evaluation times can be define in one of two ways

  1. Using artefact files When using this way, in your test execution, ensure two artifact files get created that contain the time stamps of your test start and end.

    The files that are to be created are keptn.test.starttime and keptn.test.endtime and need to contain the UTC date in the following format: 2021-04-22T15:31:38Z. They can be generated using date --utc +%FT%TZ. In the sample .gitlab-ci.yaml file you can find an example using before_script and after_script blocks. In the artifacts block they will be added for futher use in the next job.

    run-tests:
      extends: .run-jmeter
      before_script: 
        - echo $(date --utc +%FT%TZ) > keptn.test.starttime
      after_script: 
        - echo $(date --utc +%FT%TZ) > keptn.test.endtime
      stage: test   
      environment:
        name: test
      artifacts:
        paths:
        - keptn.test.starttime
        - keptn.test.endtime
    

    Set the variable KEPTN_EVAL_MODE to from_file, which is also the default.

  2. Setting variables on the stage By setting the variable KEPTN_EVAL_MODE to custom_range, you can use the additional variables KEPTN_EVAL_START and KEPTN_EVAL_END to set start and end times in UTC date in the following format: 2021-04-22T15:31:38Z. They can be generated using date --utc +%FT%TZ

Setting timestamps for evaluation with custom time zone

All variables including time information and expanded at runtime will by default use UTC. A different timezone can be set by adding TZ=<timezone abbreviation - OR - name in tz database> before date is called. For example:

run-tests:
  extends: .run-jmeter
  before_script: 
    - echo $(TZ=America/New_York date +%FT%TZ) > keptn.test.starttime
  after_script: 
    - echo $(TZ=America/New_York date +%FT%TZ) > keptn.test.endtime
  stage: test   
  environment:
    name: test
  artifacts:
    paths:
    - keptn.test.starttime
    - keptn.test.endtime

Tag summary

Content type

Image

Digest

sha256:3c4a48261

Size

18.7 MB

Last updated

over 3 years ago

docker pull dynatraceace/keptn-gitlab-runner:dev