Project

Profile

Help

How to write test scenarios in jenkins job builder tasks (yaml)

Introduction

This article describes useful commands and patterns for testing JJB and YAML related tasks.

Possbile options

Validate job(s)

  1. This option is madatory - all pushed yamls should be valid.
  2. Do not try to validate directly any file which are not maxscale-jobs/*.yaml - it is meaningless.
  3. Before calling validator ensure that your current directory is the root directory of your local maxscale-jenkins-jobs repo.

One job:

cd <maxscale-jenkins-jobs repo root >
../jjg/scripts/validate_yaml.sh maxscale-jobs/<job_name>.yaml

All jobs (check for errors):

cd <maxscale-jenkins-jobs repo root >
ls -d maxscale_jobs/*.yaml | xargs -I@ sh -c "printf '\nChecking @\n'; ../jjg/scripts/validate_yaml.sh @ 2>&1" | grep -i error 

All jobs (detailed log view):

cd <maxscale-jenkins-jobs repo root >
ls -d maxscale_jobs/*.yaml | xargs -I@ sh -c "printf '\nChecking @\n'; ../jjg/scripts/validate_yaml.sh @ 2>&1" | less

Job subset (check for errors):

cd <maxscale-jenkins-jobs repo root >
ls -d maxscale_jobs/*.yaml | grep build | xargs -I@ sh -c "printf '\nChecking @\n'; ../jjg/scripts/validate_yaml.sh @ 2>&1" | grep -i error 

Expected result - logs does not contain any errors,

Update job

Preparation

Create config.maxscale-jenkins.mariadb.com if it does not exist, template https://github.com/OSLL/jjg/blob/master/test_configs/jenkins.ini.template

Do not update any jobs on max-tst01 without recieving direct and transparent permission from Timofey Turenko.

Update job(s)

Steps:

cd <maxscale-jenkins-jobs repo root >
../jjg/scripts/ud_job.sh config.maxscale-jenkins.ini update maxscale_jobs/<job_name>.yaml

or

cd <maxscale-jenkins-jobs repo root >
ls -d maxscale_jobs/*.yaml | grep <pattern> | xargs -I@ sh -c "printf '\nChecking @\n';../jjg/scripts/ud_job.sh config.maxscale-jenkins.ini update  @ 2>&1" | less

You also can to modify by hand already updated job on maxscale-jenkins to replace missing scripts/speed up job execution/recieve needed build status/monitor other repository.

OR you can provide mock job that tests particular aspects of the updated one.

Expected result:
  1. ud_job command output does not contain any errors.
  2. updated job contains all needed settings/build steps/attributes (provide url for job configuration.
  3. updated job behaves as planned (fails in predictable situations, sends emails, calls special scripts and etc.). This can be proofed by providing links for its particular builds.

Links

  1. Scripts for updating and validating jenkins jobs https://github.com/OSLL/jjg/blob/master/test_configs/jenkins.ini.template