\Pipeline
Class Pipeline A Pipeline represents one action (e.g. 'Deploy'), separated out into multiple {@link PipelineStep} objects. A Pipeline acts on a single Git SHA, and processes that SHA through multiple steps (e.g. smoketesting it, loading a maintenance page up, deploying the SHA, smoketesting the site after deploy, removing the maintenance page.
Pipeline defines a series of "Steps" through the YML configuration for the "regular" execution, but it also hardcodes
rollback steps separately. These are handled in a special way if the "regular" steps fail. See beginRollback below.
The rollback step progression is handled by checkPipelineStatus as normal though.
If the regular steps fail, they must notify the pipeline via markFailed. This will either fail the pipeline or put it
in the "Rollback" state (this appends the rollback steps to the end of the step list automatically). These extra
steps are in fact no different to regular steps - they must succeed and fail in the standard way.
Regardless of the rollback outcome, the processing will always end up in finaliseRollback - either via step calling
markFailed, or by checkPipelineStatus running out of steps to run. This concludes the pipeline.
So to recap, the last functions that are called on Pipeline are:
- markComplete, if the pipeline has been successful (i.e. no rollback)
- markFailed, if a step has failed and there is no possibility of rollback.
- finaliseRollback, when rollback was executed, regardless whether it was successful or not.
Here is an example configuration that utilises all options provided by this class:
<code>
PipelineConfig:
DependsOnProject: "ss3"
DependsOnEnvironment: "deploytest"
FilteredCommits: "DNFinishedCommits"
Description: >
In order to deploy to this environment instance manager confirmation is required.<br />
Only successful deployments to the test server are permitted to be selected.
# Contacts to notify, as well as the author of this pipeline
Tests: # Smoke tests used by both rollback and smoke test
Home:
URL: http://www.mysite.com/
Videos:
URL: http://www.mysite.com/videos/
Recipients:
Success:
- success@silverstripe.com
Failure:
- errors@silverstripe.com
Abort:
- abort@silverstripe.com
RollbackStarted:
- ops@silverstripe.com
RollbackSuccess:
- ops@silverstripe.com
RollbackFailure:
- ops@silverstripe.com
Messages:
# Messages sent to all users (including <requester>)
Success: 'Deployment for <project>/<environment> has successfully completed.'
Failure: 'Deployment for <project>/<environment> has failed.'
Abort: 'Deployment for <project>/<environment> has been aborted.'
RollbackStarted: 'Deployment failed, rollback for <project>/<environment> has begun.'
RollbackSuccess: 'Rollback for <project>/<environment> has successfully completed.'
RollbackFailure: 'Rollback for <project>/<environment> has failed.'
Subjects:
# Subject line for all users
Success: 'Deployment for <project>/<environment>: Success'
Failure: 'Deployment for <project>/<environment>: Failure'
Abort: 'Deployment for <project>/<environment>: Aborted'
RollbackStarted: 'Deployment failed, rollback for <project>/<environment> has begun.'
RollbackSuccess: 'Rollback for <project>/<environment> has successfully completed.'
RollbackFailure: 'Rollback for <project>/<environment> has failed.'
ServiceArguments:
# Additional arguments that make sense to the ConfirmationMessagingService
from: admin@silverstripe.com
reply-to: noreply@silverstripe.com
RollbackStep1:
Class: RollbackStep
# ... first step to be performed conditionally (RollbackStep is expected here).
RollbackStep2:
Class: SmokeTestPipelineStep
# ... second step to be performed conditionally (SmokeTestPipelineStep is expected here).
Steps:
... named steps.
</code>
Synopsis
- // constants
- const ALERT_ABORT = 'Abort';
- const ALERT_SUCCESS = 'Success';
- const ALERT_FAILURE = 'Failure';
- const ALERT_ROLLBACK_STARTED = 'RollbackStarted';
- const ALERT_ROLLBACK_SUCCESS = 'RollbackSuccess';
- const ALERT_ROLLBACK_FAILURE = 'RollbackFailure';
- // members
- private static array $db = ;
- private static array $has_one = ;
- private static array $has_many = ;
- private static array $summary_fields = ;
- private static string $default_sort = '"Created" DESC';
- private static array $cast = ;
- private static array $dependencies = ;
- private ConfirmationMessagingService $messagingService = NULL;
- protected $mergedConfig;
- // methods
- public void setMessagingService()
- public ConfirmationMessagingService getMessagingService()
- public void __isset()
- public array getReplacements()
- public string getTitle()
- public void canAbort()
- public string getRunningDescription()
- public ArrayList RunningOptions()
- public ArrayList LogOptions()
- public array getConfigData()
- public void setConfig()
- public mixed getConfigSetting()
- public void getCMSFields()
- public DNEnvironment getDependentEnvironment()
- protected PipelineStep generateStep()
- public void start()
- public void markComplete()
- public bool isComplete()
- public bool isRunning()
- public bool isActive()
- private void pushPipelineStep()
- protected void finaliseRollback()
- protected void beginRollback()
- protected void canStartRollback()
- public void markFailed()
- public bool isFailed()
- public bool isRollback()
- public void markAborted()
- protected array generateMessageTemplate()
- public array injectMessageReplacements()
- public boolean sendMessage()
- public bool isAborted()
- public void checkPipelineStatus()
- protected PipelineStep|null findNextStep()
- public PipelineStep|null findPreviousStep()
- public void log()
- public DeploynautLogFile getLogger()
- public void getDryRun()
- public void Link()
- public string StepLink()
- public void AbortLink()
- public void LogLink()
- public void LogContent()
Hierarchy
Constants
Name | Value |
---|---|
ALERT_ABORT | 'Abort' |
ALERT_SUCCESS | 'Success' |
ALERT_FAILURE | 'Failure' |
ALERT_ROLLBACK_STARTED | 'RollbackStarted' |
ALERT_ROLLBACK_SUCCESS | 'RollbackSuccess' |
ALERT_ROLLBACK_FAILURE | 'RollbackFailure' |
Members
private
- $cast
- $db — array
- $default_sort
- $dependencies — array
- $has_many — array
- $has_one — array
- $messagingService
—
ConfirmationMessagingService
Currently assigned messaging service - $summary_fields
protected
- $mergedConfig
—
array
Cached of config merged with defaults
Methods
private
- pushPipelineStep() — Push a step to the end of a pipeline
protected
- beginRollback() — Initiate a rollback. Moves the pipeline to the 'Rollback' status.
- canStartRollback() — Check if pipeline currently permits a rollback.
- finaliseRollback() — The rollback has finished - close the pipeline and send relevant messages.
- findNextStep() — Finds the next {@link PipelineStep} that needs to execute. Relies on $this->CurrentStep() being a valid step.
- generateMessageTemplate() — Finds a message template for a given role and message
- generateStep() — Generate a step from a name, config, and sort order
public
- AbortLink()
- Link()
- LogContent()
- LogLink()
- LogOptions() — Get possible logs for the currently pipeline
- RunningOptions() — Get options for the currently running pipeline, if and only if it is currently running
- StepLink() — Link to an action on the current step
- __isset()
- canAbort()
- checkPipelineStatus() — This method should be called only by the {@link CheckPipelineStatus} controller. It iterates through all the {@link PipelineStep} objects associated with this Pipeline, and finds a place where the pipeline has stalled (where one step has completed, but the next one has yet to start). It will then start the next step if required.
- findPreviousStep() — Finds the previous {@link PipelineStep} that executed. Relies on $this->CurrentStep() being a valid step.
- getCMSFields()
- getConfigData() — Get this pipeline configuration. If the configuration has been serialized and saved into the Config field, it'll use that. If that field is empty, it'll read the YAML file directly and return that instead.
- getConfigSetting() — Retrieve the value of a specific config setting
- getDependentEnvironment() — Return a dependent {@link DNEnvironment} based on this pipeline's dependent environment configuration.
- getDryRun()
- getLogger() — Returns the {@link DeploynautLogFile} instance that will actually write to this log file.
- getMessagingService()
- getReplacements() — Retrieve message template replacements
- getRunningDescription() — Get status of currently running step
- getTitle() — Title of this step
- injectMessageReplacements() — Substitute templated variables into the given message and subject
- isAborted()
- isActive() — True if the pipeline is running or doing a rollback
- isComplete()
- isFailed()
- isRollback()
- isRunning() — True if the pipeline is running but NOT doing a rollback
- log() — Write to a common log file. This log file will be the same regardless of how often this pipeline is re-created from the database. To this end, it needs to know the database ID of this pipeline instance, so that it can generate the correct filename to open.
- markAborted() — Mark this Pipeline as aborted
- markComplete() — Mark this Pipeline as completed.
- markFailed() — Notify Pipeline that a step has failed and failure processing should kick in. If rollback steps are present the pipeline will be put into 'Rollback' state. After rollback is complete, regardless of the rollback result, the pipeline will be failed.
- sendMessage() — Sends a specific message to all marked recipients, including the author of this pipeline
- setConfig()
- setMessagingService()
- start() — Starts the pipeline process.