Add variables to project

This adds a "vars:" entry to projects and project-templates to make
available global values for each job.  This can be useful to avoid
repeating the same variable definitions for the same job in different
pipelines, or to pass a project-specific value to jobs in a templating
situation.

Change-Id: I9fb468743a21067773979d113e714b5c3e908d02
This commit is contained in:
Ian Wienand
2018-07-20 15:17:28 +10:00
committed by Monty Taylor
parent 0e48355003
commit 8d80ec2ba8
7 changed files with 155 additions and 4 deletions

View File

@@ -1203,6 +1203,13 @@ pipeline.
Cherry-picks each change onto the branch rather than
performing any merges.
.. attr:: vars
:default: None
A dictionary of variables to be made available for all jobs in
all pipelines of this project. For more information see
:ref:`variable inheritance <user_jobs_variable_inheritance>`.
.. attr:: <pipeline>
Each pipeline that the project participates in should have an

View File

@@ -78,6 +78,8 @@ behavior.
.. TODO: document src (and logs?) directory
.. _user_jobs_variable_inheritance:
Variables
---------
@@ -89,6 +91,7 @@ order of precedence is:
#. :ref:`Job extra variables <user_jobs_job_extra_variables>`
#. :ref:`Secrets <user_jobs_secrets>`
#. :ref:`Job variables <user_jobs_job_variables>`
#. :ref:`Project variables <user_jobs_project_variables>`
#. :ref:`Parent job results <user_jobs_parent_results>`
Meaning that a site-wide variable with the same name as any other will
@@ -156,6 +159,46 @@ They are added to the ``vars`` section of the inventory file under the
``all`` hosts group, so they are available to all hosts. Simply refer
to them by the name specified in the job's ``vars`` section.
.. _user_jobs_project_variables:
Project Variables
~~~~~~~~~~~~~~~~~
Any variables specified in the project definition (using the
:attr:`project.vars` attribute) are available to jobs as Ansible host
variables in the same way as :ref:`job variables
<user_jobs_job_variables>`. Variables set in a ``project-template``
are merged into the project variables when the template is included by
a project.
.. code-block:: yaml
- project-template:
name: sample-template
description: Description
vars:
var_from_template: foo
post:
jobs:
- template_job
release:
jobs:
- template_job
- project:
name: Sample project
description: Description
templates:
- sample-template
vars:
var_for_all_jobs: value
check:
jobs:
- job1
- job2:
vars:
var_for_all_jobs: override
.. _user_jobs_parent_results:
Parent Job Results