This module provides a set of tools, via CD4PE, for creating your own custom CD4PE deployment policies as well as our 4 built-in policies: Feature branch, Temporary branch, Direct, and Eventual consistency.
-
Get started with a custom deployment policy by creating a Puppet Plan in the
plans/directory. -
You'll have access to all of the functions listed in our REFERENCE.md to perform deployment operations (e.g. pinning nodes to an environment group or getting information about an environment group)
-
Deployment policies will run inside a CD4PE context with certain environment variables available.
CD4PE_PIPELINE_ID: NOT AVAILABLE IN MANUAL DEPLOYMENTS, a unique identifier for the current pipeline.MODULE_NAME: the name of the module being deployedCONTROL_REPO_NAME: the name of the control repo being deployed. In the case of a module feature branch deployment, this is the name of the control repo the deployment is based off of.BRANCH: the name of the branch you are deploying from; your pipeline branchCOMMIT: HEAD commit SHA of the branch you are deploying fromNODE_GROUP_ID: alpha-numberic ID of the node group you are deploying toNODE_GROUP_ENVIRONMENT:the environment of the node group you are deploying toREPO_TARGET_BRANCH: name of the source control branch that represents the target environmentENVIRONMENT_PREFIX: if you are deploying to a prefixed environment, this is that prefixREPO_TYPE: will either be "CONTROL_REPO" or "MODULE"DEPLOYMENT_DOMAIN: domain of the workspace that initiates the deploymentDEPLOYMENT_ID: unique ID of the deploymentDEPLOYMENT_TOKEN: the auth token that authenticates deployment tasks against CD4PEDEPLOYMENT_OWNER: user that intitiates the deployment- Results - a set of variables will also be generated during the pipeline run to represent stage/event results, they have two parts:
CD4PE_STAGE_<stage_number>_: the variable name prefix with the stage numberDEPLOYMENT_<deployment_number>_RESULT,JOB_<job_number>_RESULT,IMPACT_ANALYSIS_<analysis_number>_RESULT: the task type with its sequence number.- Possible result values
DONE: task completed with no errorsFAILED: task failedCANCELED: task was canceled either manually or because a preceding task failedDECLINED: task was declined during the approval process
- Examples:
- The declined result of the first deployment in the second stage would be
CD4PE_STAGE_2_DEPLOYMENT_1_RESULTwith a value ofDECLINED - The failure result of the third job in the first stage would be
CD4PE_STAGE_1_JOB_3_RESULTwith a value ofFAILED - The success result of the first impact analysis in the third stage would be
CD4PE_STAGE_3_IMPACT_ANALYSIS_1_RESULTwith a value ofDONE
- The declined result of the first deployment in the second stage would be
-
Use any of the functions in this module (see REFERENCE.md to build your deployment policy.
$result = get_node_group('abcd-1234-efgh-56789') if($result['error']){ fail_plan("Could not get node group! ${result[error][message]}") } -
Take a look at our built-in policies for examples to help you get started.
Most functions available in this module will always return a CD4PEFunctionResult that contains:
- result
- error: { message, code }
{
result: {
approvalDecision: "APPROVED"
},
error: nil
}{
result: nil,
error: {
message: "Something went wrong",
code: "SomeErrorCode",
}
}ParameterMissing- The CD4PE API was expecting a parameter that was not provided.
ParameterParsing- The CD4PE API was unable to parse the provided parameter value.
FunctionFailure- CD4PE was unable to complete the function's primary purpose (e.g. run_puppet() failed to run Puppet)
See our REFERENCE.md for reference documentation.
-
Fork the module repository on GitHub and clone to your workspace
-
Make your changes!
-
Commit your changes and push them to your fork
-
Open a PR against puppetlabs/master
-
Update the docs by running
bundle exec puppet strings generate --format markdownand commit the changes. -
Merge to master after receiving a +1 on your PR.
To get tests to run, do the following from the root of this repository
bundle installbundle exec rake spec
Other documentation around testing: