Test Puppet code with jobs
Jobs are fully customizable tests for your Puppet code. You can create a job that runs any sort of test you want, including module validation, linting, and more.
What is a job?
In Continuous Delivery for Puppet Enterprise (PE), jobs test your Puppet code. You create and store jobs in the web UI, where you can run them on demand and add them to automated pipelines to run tests every time new code is committed to a repository.
Where do jobs run?
- Global shared job hardware: These are job hardware servers configured in the root console and available to all workspaces in your Continuous Delivery for PE installation.
- Workspace hardware: These are job hardware servers configured in a specific workspace and available to members of that workspace, but not available to other workspaces.
For more information about setting up job hardware, go to Configure job hardware.
Global shared job hardware uses a shared Docker image set in the root console. The default image used for Docker-based jobs is puppet/puppet-dev-tools:4.x. You can find details on the available commands in the image documentation.
When configuring a job to run on workspace hardware, you can use the shared Docker image or environment variables in the job to overwrite the default image. However:
Add secrets to jobs
You can add secrets, such as tokens and certificates, to Continuous Delivery for Puppet Enterprise (PE) jobs. Jobs can use secrets when they run.
puppetlabs-cd4pe_jobs
module version 1.6.0
or higher. You install this module when you Configure job hardware.Secrets are limited to the job where you create them. If a secret is applicable to multiple jobs, you must add that secret to each relevant job.
When you run jobs that use secrets, you can see where jobs use secrets in the jobs' logs. Sensitive values are redacted.
Using a custom image to test Puppet 8
The puppet/puppet-dev-tools:4.x
image that jobs use by default does
not support testing modules with Puppet 8. To test with Puppet 8, create a
custom job that uses the puppet/puppet-dev-tools:puppet8
image. This image
contains PDK 3, Puppet 8, and Onceover 3.22. See the
puppet-dev-tools readme for the full list of
commands provided by the image.
To create a custom job using the Puppet 8 image:
- In the Continuous Delivery for Puppet Enterprise (PE) web UI, click Jobs.
- Click New Job.
- Enter your job’s info, any commands you want to run, and any secrets you need.
- Select Run on <workspace> hardware and the Docker hardware capability.
- Toggle the switch to run this job in a Docker container and select Custom image.
-
Specify
puppet/puppet-dev-tools:puppet8
as the custom image name. - Click Save Job.
Pre-built job reference
Use these job templates to set up Docker-based jobs for testing control repos and modules. These jobs run inside a Docker container and require job hardware that has a Docker capability.
Validate the syntax of a control repo's Puppetfile
- In the Continuous Delivery for PE web UI, click .
- Complete the fields:
- Name: control-repo-puppetfile-syntax-validate
- Description: Validate that a control repo’s Puppetfile is syntactically correct
-
Job commands:
rake -f /Rakefile r10k:syntax
- Where can this job run?: Select Run on <WORKSPACE_NAME> hardware
- Hardware capabilities: Select Docker and click Apply
- Docker configuration: Enable the Run this job in a Docker container switch and select Default image (puppet/puppet-dev-tools)
- Click Save job.
Validate the syntax of a control repo's Puppet templates
- In the Continuous Delivery for PE web UI, click .
- Complete the fields:
- Name: control-repo-template-syntax-validate
- Description: Validate that a control repo’s Puppet templates are syntactically correct.
-
Job commands:
rake -f /Rakefile syntax:templates
- Where can this job run?: Select Run on <WORKSPACE_NAME> hardware
- Hardware capabilities: Select Docker and click Apply
- Docker configuration: Enable the Run this job in a Docker container switch and select Default image (puppet/puppet-dev-tools)
- Click Save job.
Validate the syntax of a control repo's Hiera data
- In the Continuous Delivery for PE web UI, click .
- Complete the fields:
- Name: control-repo-hiera-syntax-validate
- Description: Validate that a control repo’s Hiera data is syntactically correct.
-
Job commands:
rake -f /Rakefile syntax:hiera
- Where can this job run?: Select Run on <WORKSPACE_NAME> hardware
- Hardware capabilities: Select Docker and click Apply
- Docker configuration: Enable the Run this job in a Docker container switch and select Default image (puppet/puppet-dev-tools)
- Click Save job.
Validate the syntax of a control repo's Puppet manifest code
- In the Continuous Delivery for PE web UI, click .
- Complete the fields:
- Name: control-repo-manifest-validate
- Description: Validate that a control repo’s Puppet manifest code is syntactically correct
-
Job commands:
rake -f /Rakefile syntax:manifests
- Where can this job run?: Select Run on <WORKSPACE_NAME> hardware
- Hardware capabilities: Select Docker and click Apply
- Docker configuration: Enable the Run this job in a Docker container switch and select Default image (puppet/puppet-dev-tools)
- Click Save job.
Validate the syntax of a module's Puppet manifest code
- In the Continuous Delivery for PE web UI, click .
- Complete the fields:
- Name: module-pdk-validate
- Description: Validate that a module’s Puppet manifest code is syntactically correct
-
Job commands:
pdk validate --parallel
- Where can this job run?: Select Run on <WORKSPACE_NAME> hardware
- Hardware capabilities: Select Docker and click Apply
- Docker configuration: Enable the Run this job in a Docker container switch and select Default image (puppet/puppet-dev-tools)
- Click Save job.
Run rspec-puppet unit tests on a module
- In the Continuous Delivery for PE web UI, click .
- Complete the fields:
- Name: module-rspec-puppet
- Description: Run rspec-puppet unit tests on a module
-
Job commands:
pdk test unit
- Where can this job run?: Select Run on <WORKSPACE_NAME> hardware
- Hardware capabilities: Select Docker and click Apply
- Docker configuration: Enable the Run this job in a Docker container switch and select Default image (puppet/puppet-dev-tools)
- Click Save job.
Sample non-Docker-based module jobs
You can use these Continuous Delivery for Puppet Enterprise (PE) job templates as-is or customize them to your deployment's needs. To add jobs, go to in the Continuous Delivery for PE web UI.
$REPO_DIR
environment
variable to reference the directory containing the relevant module repo.Puppet Development Kit validation tests
These jobs validate module code against Puppet Development Kit (PDK). Use the configuration for your operating system.
- Job name: module-pdk-validate-linux
- Description: Validate via PDK
-
Job commands:
pdk validate
- Hardware capabilities: Linux
- Job name: module-pdk-validate-windows
- Description: Validate via PDK
-
Job commands:
powershell.exe -c "pdk validate"
- Hardware capabilities: Windows
To use these jobs you must Install
PDK and install puppet-agent
on the job
hardware.
Puppet Development Kit
rspec-puppet
tests
These jobs run unit tests on your module code with rspec-puppet
.
Use the configuration for your operating system.
- Job name: module-pdk-test-unit-linux
- Description: Run unit tests via PDK
-
Job commands:
pdk test unit
- Hardware capabilities: Linux
- Job name: module-pdk-test-unit-windows
- Description: Run unit tests via PDK
-
Job commands:
powershell.exe -c "pdk test unit"
- Hardware capabilities: Windows
To use these jobs you must Install
PDK and install puppet-agent
on the job
hardware.
Sample non-Docker-based control repo jobs
You can use these Continuous Delivery for Puppet Enterprise (PE) job templates as-is or customize them to your deployment's needs. To add jobs, go to in the Continuous Delivery for PE web UI.
$REPO_DIR
environment variable to reference
the directory containing the relevant module repo.Syntax validation
This job validates the syntax of everything in your control repo.
To use this job you must use a *nix host and install puppet-agent
on the job hardware.
- Job name: control-repo-validate-linux
- Description: Validate syntax
- Hardware capabilities: Linux
-
Job commands:
#!/bin/bash shopt -s globstar nullglob green="$(tput setaf 2)" red="$(tput setaf 1)" reset="$(tput sgr0)" for f in **/**pp; do [[ $f =~ plans/ ]] && continue if puppet parser validate "$f"; then echo "${green}SUCCESS: $f${reset}" else echo "${red}FAILED: $f${reset}" failures+=("$f") fi done if (( ${#failures[@]} > 0 )); then echo "${red}Syntax validation on the Control Repo has failed in the following manifests:" echo -e "\t ${failures[@]}${reset}" exit 1 else echo "${green}Syntax validation on the Control Repo has succeeded.${reset}" fi
Puppet linter
This job checks the Puppet code in your control repo for programming and stylistic errors.
To use this job you must use a *nix host and install puppet-agent
on the job hardware.
- Job name: control-repo-lint-linux
- Description: Lint Puppet code
- Hardware capabilities: Linux
-
Job commands:
#!/bin/bash shopt -s globstar nullglob green="$(tput setaf 2)" red="$(tput setaf 1)" reset="$(tput sgr0)" sudo /opt/puppetlabs/puppet/bin/gem install puppet-lint || { echo "${red}Failed to install puppet-lint gem" exit 2 } LINT_OPTS=("--fail-on-warnings" "--no-documentation-check" "--no-140chars-check" "--no-autoloader_layout-check" "--no-class_inherits_from_params_class-check") for f in **/**pp; do [[ $f =~ plans/ ]] && continue if /opt/puppetlabs/puppet/bin/puppet-lint "${LINT_OPTS[@]}" "$f"; then echo "${green}SUCCESS: $f${reset}" else echo "${red}FAILED: $f${reset}" failures+=("$f") fi done if (( ${#failures[@]} > 0 )); then echo "${red}Puppet-lint validation on the Control Repo has failed in the following manifests:" echo -e "\t ${failures[@]}${reset}" exit 1 else echo "${green}Puppet-lint validation on the Control Repo has succeeded.${reset}" fi