-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add logic to advance waiting steps on event. * Add advance pipeline step. * Add documentation for new step. * Update deps to latest.
- Loading branch information
Showing
33 changed files
with
992 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Advance Pipeline Step | ||
|
||
[cloud-manager-events]: https://www.adobe.io/apis/experiencecloud/cloud-manager/docs.html#!AdobeDocs/cloudmanager-api-docs/master/receiving-events.md | ||
|
||
This step will advance the Cloud Manager pipeline. That pipeline must be in the proper state based on the actions specified in the step configuration. If the Cloud Manager pipeline is not in a valid state for advancing, then this step will fail the build. | ||
|
||
**Note**: *This feature requires that either a [Pipeline Start Trigger](/doc/trigger/start-pipeline/README.md) or a [Pipeline Start Builder](/doc/builder/start-pipeline/README.md) is defined earlier in the pipeline.* | ||
|
||
## Usage | ||
|
||
Syntax: | ||
|
||
``` | ||
acmAdvancePipeline( | ||
actions: ['codeQuality', 'approval'] | ||
) | ||
``` | ||
|
||
### Optional Properties | ||
|
||
* `actions`: Optional list of [actions][cloud-manager-events] to which this step will respond. | ||
* An empty list constitutes all actions. | ||
* At this time only two values are valid: *codeQuality* and *approval* | ||
|
||
## Use Cases | ||
|
||
### Advance Pipeline After Pause | ||
|
||
The intent of this step is to be used in combination with a `acmPipelineStepState` step where the Cloud Manager Pipeline has paused, and offline actions are necessary before advancing the remote Pipeline. | ||
|
||
For example: Wait for the Cloud Manager pipeline to reach the Approval step, allowing for out-of-band operations such as performance or load testing using third party tools. Once those are successful advance the pipeline. | ||
|
||
``` | ||
acmPipelineStepState(actions: ['approval'], waitingPause: false) | ||
... | ||
// Do other actions here | ||
... | ||
acmAdvancePipeline(actions: ['approval']) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/main/java/io/jenkins/plugins/adobe/cloudmanager/step/AdvancePipelineStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package io.jenkins.plugins.adobe.cloudmanager.step; | ||
|
||
/*- | ||
* #%L | ||
* Adobe Cloud Manager Plugin | ||
* %% | ||
* Copyright (C) 2020 - 2021 Adobe Inc. | ||
* %% | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* #L% | ||
*/ | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import javax.annotation.Nonnull; | ||
|
||
import hudson.AbortException; | ||
import hudson.Extension; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import io.adobe.cloudmanager.StepAction; | ||
import io.jenkins.plugins.adobe.cloudmanager.step.execution.AdvancePipelineExecution; | ||
import org.jenkinsci.plugins.workflow.steps.Step; | ||
import org.jenkinsci.plugins.workflow.steps.StepContext; | ||
import org.jenkinsci.plugins.workflow.steps.StepDescriptor; | ||
import org.jenkinsci.plugins.workflow.steps.StepExecution; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
|
||
/** | ||
* {@link Step} which will advance the current Cloud Manager pipeline execution in Cloud Manager Build context | ||
* | ||
* By default it will advance the Pipeline regardless of the current state. To narrow the scope, specify the {@code action} context. | ||
*/ | ||
public class AdvancePipelineStep extends Step { | ||
private static final List<StepAction> ALLOWED_ACTIONS = Arrays.asList(StepAction.codeQuality, StepAction.approval); | ||
|
||
private List<StepAction> actions = new ArrayList<>(ALLOWED_ACTIONS);; | ||
|
||
@DataBoundConstructor | ||
public AdvancePipelineStep() { | ||
|
||
} | ||
|
||
/** | ||
* List of actions to which this Step will respond. <strong>Default:</strong> {@code codeQuality} and {@code approval} actions. | ||
*/ | ||
@Nonnull | ||
public List<StepAction> getActions() { | ||
return actions; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setActions(List<StepAction> actions) { | ||
if (actions != null && !actions.isEmpty()) { | ||
this.actions = actions; | ||
} | ||
} | ||
|
||
@Override | ||
public StepExecution start(StepContext context) throws Exception { | ||
for (StepAction action : actions) { | ||
if (!ALLOWED_ACTIONS.contains(action)) { | ||
throw new AbortException(Messages.ApprovePipelineStep_error_invalidAction(action)); | ||
} | ||
} | ||
return new AdvancePipelineExecution(context, actions); | ||
} | ||
|
||
@Extension | ||
public static final class DescriptorImpl extends StepDescriptor { | ||
@Override | ||
public String getFunctionName() { | ||
return "acmAdvancePipeline"; | ||
} | ||
|
||
@Override | ||
public Set<? extends Class<?>> getRequiredContext() { | ||
return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(Run.class, TaskListener.class))); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getDisplayName() { | ||
return Messages.ApprovePipelineStep_displayName(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...n/java/io/jenkins/plugins/adobe/cloudmanager/step/execution/AdvancePipelineExecution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package io.jenkins.plugins.adobe.cloudmanager.step.execution; | ||
|
||
/*- | ||
* #%L | ||
* Adobe Cloud Manager Plugin | ||
* %% | ||
* Copyright (C) 2020 - 2021 Adobe Inc. | ||
* %% | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* #L% | ||
*/ | ||
|
||
import java.util.List; | ||
|
||
import hudson.AbortException; | ||
import io.adobe.cloudmanager.CloudManagerApi; | ||
import io.adobe.cloudmanager.CloudManagerApiException; | ||
import io.adobe.cloudmanager.PipelineExecution; | ||
import io.adobe.cloudmanager.PipelineExecutionStepState; | ||
import io.adobe.cloudmanager.StepAction; | ||
import io.jenkins.plugins.adobe.cloudmanager.CloudManagerPipelineExecution; | ||
import org.jenkinsci.plugins.workflow.steps.StepContext; | ||
|
||
/** | ||
* Execution for a {@link io.jenkins.plugins.adobe.cloudmanager.step.AdvancePipelineStep}, advancing the remote Cloud Manager pipeline. | ||
*/ | ||
public class AdvancePipelineExecution extends AbstractStepExecution { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private final List<StepAction> actions; | ||
|
||
public AdvancePipelineExecution(StepContext context, List<StepAction> actions) { | ||
super(context); | ||
this.actions = actions; | ||
} | ||
|
||
@Override | ||
public void doStart() throws Exception { | ||
try { | ||
CloudManagerPipelineExecution build = getBuildData().getCmExecution(); | ||
CloudManagerApi api = getApi(); | ||
PipelineExecution pe = api.getExecution(build.getProgramId(), build.getPipelineId(), build.getExecutionId()); | ||
|
||
PipelineExecutionStepState step = api.getCurrentStep(pe); | ||
StepAction stepAction = StepAction.valueOf(step.getAction()); | ||
if (actions.contains(stepAction)) { | ||
getTaskListener().getLogger().println(Messages.AdvancePipelineExecution_info_advancingPipeline(stepAction)); | ||
api.advanceExecution(pe); | ||
getContext().onSuccess(null); | ||
} else { | ||
throw new AbortException(Messages.AdvancePipelineExecution_error_invalidPipelineState(stepAction)); | ||
} | ||
} catch (CloudManagerApiException e) { | ||
throw new AbortException(e.getLocalizedMessage()); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isAsync() { | ||
return false; | ||
} | ||
} |
Oops, something went wrong.