2 | Show SCM change log for the pipeline.
3 | If a repository browser is configured, a link to the changes in the repository browser will be created.
4 |
2 | Enable pagination in normal view, to allow navigation to older pipeline runs which are not displayed on the first page. Not available in full screen view.
3 |
2 | Limits the number of pipelines shown in the view, regardless of how many pipelines are configured.
3 | A negative value will not enforce a limit.
4 |
2 | Limits the number of pipelines shown in the view, regardless of how many pipelines are configured.
3 | A negative value will not enforce a limit.
4 |
2 | First job in the pipeline. Usually the build/compile job.
3 | The build number/build display name will be used as the version in later tasks or stages.
4 |
2 | Show SCM change log for the first job in the pipeline.
3 | If a repository browser is configured, a link to the changes in the repository browser will be created.
4 |
2 | Changes behaviour of links in delivery pipeline view to go directly to the console log for a particular pipeline run.
3 | Allows for quicker navigation to log outputs.
4 |
2 | If enabled the job will create a version based on the template.
3 | The version will be set to the environment variable PIPELINE_VERSION and will also be set in the downstream jobs.
4 |
2 | Show total build time for a pipeline run.
3 | If there are multiple routes in a pipeline, total build time is calculated as the sum of the build times in the longest route.
4 |
2 | Use relative links for jobs in this pipeline view to allow for easier navigation.
3 | When drilling down on a job from the pipeline view, the name of the view is shown in the navigation menu.
4 |
2 | Final job to display in the pipeline view regardless of its downstream jobs.
3 | Useful if you have jobs that should be excluded from pipeline or you want to split sequence of jobs into multiple pipelines.
4 |
3 | Continuous Delivery pipelines, perfect for visualization on information radiators.
4 | Shows one or more delivery pipeline instances, based on Jenkins pipelines (created using the Pipeline or Workflow plugin).
5 |
3 | Continuous Delivery pipelines, perfect for visualization on information radiators.
4 | Shows one or more delivery pipeline instances, based on traditional Jenkins jobs
5 | with upstream/downstream dependencies.
6 |
2 | Show avatars pictures instead of names of the people involved in a pipeline instance.
3 | Use Avatar Plugin or Gravatar plugin or similar to set avatar picture for contributors.
4 |
5 | Expands to the value of the version that was passed during built. Note that this does not include any variables set by the build scripts themselves, only those set by Jenkins and other plugins.
6 |
7 |
8 |
Parameters
9 |
10 |
stripSnapshot
11 |
12 | If specified, this token expands to the value of the version without the -SNAPSHOT part, such as '1.0'.
13 | Otherwise, it only expands to the unchanged value, such as '1.0-SNAPSHOT'.
14 |
17 |
18 |
--------------------------------------------------------------------------------
/license-header.txt:
--------------------------------------------------------------------------------
1 | This file is part of ${project.name}.
2 |
3 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
4 | it under the terms of the GNU General Public License as published by
5 | the Free Software Foundation, either version 3 of the License, or
6 | (at your option) any later version.
7 |
8 | ${project.name} is distributed in the hope that it will be useful,
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | GNU General Public License for more details.
12 |
13 | You should have received a copy of the GNU General Public License
14 | along with ${project.name}.
15 | If not, see .
16 |
--------------------------------------------------------------------------------
/travis_deploy_key.pub:
--------------------------------------------------------------------------------
1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD83Mqm9eeCBE0qbUw/6z4GetijacBxebJN1801qxJPYUeVt5bgNP+NLV53qoUEevHg85uqtcljtAaihb5iGOklPCmm94HCNvBZ/Gxz8Vq+soXsmioB2+OwLY9cxqc424wGK2RoRzxT99/L9uwJbixYL0V5ctiAS+0EiWhlaikEOx/+aob6jzJ5pjgfS3Ef/lFbV5SJKcnp5OoKc5i+BJlhW4ap/MoigzpQ6/3mNhFunVt6W7U1bYKSarSZqM0AIHf3QlHrb0VfOahWCg0JKGuDIO4rn873NFzt9TNHHjJn8DOQJIcYObfZxHHxso/gIYuhul7vob3EpTfG7W61AYB/3hK8Y9lZygUrBk9U3eDyF/8OeQwZl4GYeCKEHPIAHnmlCSruTIAs15MqzCOsQ0lzEGK1MhMFWR8G+heiV7D1XJmdoEK/8eR/o7JGIU+t1CsMJixuoHwpkBVafz+2Uw56JfcfWjaCRmoSW3KdQIj6kwJCKDSFz/i9N4Mh+MX7/uUa8+KsZ0Eo9Pq+kMwySGNiFI325LfqYIq5sa8jTqc5jPK3eu2fd/sxaOdi2YINj9RhljM19aXtjvaC9hM6rZb0P7FVPbXsBPagT192yTpQjKOURvLkZUk5NtKCEVLCQOu0SZ7xB9YPOdZJjA1g3ThFJWHeaeYnoDDyoAjToKRR3w== travis@diabol.se
2 |
--------------------------------------------------------------------------------
/examples/view.yaml:
--------------------------------------------------------------------------------
1 | views:
2 | - delivery_pipeline:
3 | filter-executors: false
4 | filter-queue: false
5 | folder: false
6 | components:
7 | - name: 'Example pipeline'
8 | first-job: 'example-str-build'
9 | name: 'Pipeline view'
10 | build-view-title: 'Test Build Pipeline'
11 | number-of-pipelines: 3
12 | show-aggregated-pipeline: false
13 | number-of-columns: 1
14 | sorting: none
15 | show-avatars: false
16 | update-interval: 2
17 | show-changes: true
18 | allow-manual-triggers: true
19 | show-total-buildtime: true
20 | allow-rebuild: true
21 | allow-pipeline-start: true
22 | show-description: false
23 | show-promotions: false
24 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM jenkins/jenkins:2.107.3-alpine
2 | MAINTAINER Diabol AB - https://www.diabol.se - https://github.com/Diabol
3 |
4 | USER jenkins
5 | COPY docker/plugins.txt /usr/share/jenkins/ref/
6 | RUN /usr/local/bin/plugins.sh /usr/share/jenkins/ref/plugins.txt
7 | COPY docker/generate-jobs.xml /usr/share/jenkins/ref/jobs/generate-jobs/config.xml
8 | COPY examples/demo.groovy /usr/share/jenkins/ref/jobs/generate-jobs/workspace/demo.groovy
9 | COPY docker/startup.groovy /usr/share/jenkins/ref/init.groovy.d/startup.groovy
10 | COPY target/delivery-pipeline-plugin.hpi /usr/share/jenkins/ref/plugins/delivery-pipeline-plugin.hpi
11 |
12 | USER root
13 | RUN chown -R jenkins:jenkins /usr/share/jenkins/ref/plugins/delivery-pipeline-plugin.hpi
14 |
15 | USER jenkins
16 |
17 |
--------------------------------------------------------------------------------
/src/main/resources/se/diabol/jenkins/pipeline/DeliveryPipelineView/legend.jelly:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
In a delivery pipeline view this job will be shown as a task in a stage. Enter the name for the task. You can use all environment and build variables using Token Macro Plugin
10 | In a build Delivery Pipeline View this description will be shown as an description for the task. Description can be customized with all environment and build variables using Token Macro Plugin
11 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/main/resources/se/diabol/jenkins/pipeline/PipelineProperty/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/domain/PipelineException.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain;
19 |
20 | public class PipelineException extends Exception {
21 |
22 | public PipelineException(String message) {
23 | super(message);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/docker/plugins.txt:
--------------------------------------------------------------------------------
1 | credentials:2.1.11
2 | job-dsl:1.44
3 | junit:1.20
4 | structs:1.10
5 | javadoc:1.0
6 | display-url-api:0.2
7 | mailer:1.18
8 | matrix-project:1.4
9 | matrix-auth:2.2
10 | maven-plugin:2.10
11 | script-security:1.39
12 | ssh-credentials:1.10
13 | scm-api:2.2.6
14 | git-client:1.17.1
15 | git:2.3.5
16 | build-name-setter:1.3
17 | ace-editor:1.0.1
18 | jquery-detached:1.2.1
19 | workflow-support:2.17
20 | workflow-api:2.25
21 | workflow-step-api:2.13
22 | workflow-job:2.17
23 | workflow-cps:2.43
24 | workflow-scm-step:2.4
25 | workflow-durable-task-step:2.19
26 | workflow-multibranch:2.17
27 | workflow-basic-steps:2.6
28 | pipeline-input-step:2.0
29 | pipeline-stage-step:2.2
30 | pipeline-graph-analysis:1.1
31 | momentjs:1.1
32 | handlebars:1.1
33 | durable-task:1.18
34 | branch-api:2.0.18
35 | build-pipeline-plugin:1.5.7.1
36 | pipeline-stage-view:2.5
37 | pipeline-rest-api:2.5
38 | promoted-builds:2.27
39 | token-macro:1.12.1
40 | jquery:1.7.2-1
41 | parameterized-trigger:2.26
42 | cloudbees-folder:6.1.2
43 | dashboard-view:2.9.2
44 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/workflow/step/TaskAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.workflow.step;
19 |
20 | import hudson.model.Action;
21 |
22 | public interface TaskAction extends Action {
23 |
24 | String getTaskName();
25 |
26 | Long getFinishedTime();
27 |
28 | void setFinishedTime(Long finishedTime);
29 | }
30 |
--------------------------------------------------------------------------------
/docker/generate-jobs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | false
6 |
7 |
8 | true
9 | false
10 | false
11 | false
12 |
13 | false
14 |
15 |
16 | *.groovy
17 | false
18 | false
19 | IGNORE
20 | IGNORE
21 | JENKINS_ROOT
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/domain/status/StatusType.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain.status;
19 |
20 | public enum StatusType {
21 | IDLE,
22 | RUNNING,
23 | QUEUED,
24 | SUCCESS,
25 | UNSTABLE,
26 | FAILED,
27 | CANCELLED,
28 | DISABLED,
29 | NOT_BUILT,
30 | PAUSED_PENDING_INPUT
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/sort/ComponentComparatorDescriptor.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.sort;
19 |
20 | import hudson.model.Descriptor;
21 |
22 | public abstract class ComponentComparatorDescriptor extends Descriptor {
23 |
24 | public abstract GenericComponentComparator createInstance();
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/trigger/TriggerException.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.trigger;
19 |
20 | public class TriggerException extends Exception {
21 |
22 | public TriggerException(String message) {
23 | super(message);
24 | }
25 |
26 | public TriggerException(String message, Throwable cause) {
27 | super(message, cause);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/domain/StageEdgeFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain;
19 |
20 | import org.jgrapht.EdgeFactory;
21 |
22 | public class StageEdgeFactory implements EdgeFactory {
23 |
24 | @Override
25 | public Edge createEdge(Stage sourceVertex, Stage targetVertex) {
26 | return new Edge(sourceVertex, targetVertex);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/workflow/util/Name.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.workflow.util;
19 |
20 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
21 |
22 | public final class Name {
23 |
24 | public static String of(WorkflowRun build) {
25 | if (build == null) {
26 | return null;
27 | }
28 | return build.getParent().getFullName();
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/util/PipelineUtilsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.util;
19 |
20 | import org.junit.Test;
21 | import se.diabol.jenkins.pipeline.test.TestUtil;
22 |
23 | public class PipelineUtilsTest {
24 |
25 | @Test
26 | public void testValidUtilClass() throws Exception {
27 | TestUtil.assertUtilityClassWellDefined(PipelineUtils.class);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/core/GenericPipeline.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.core;
19 |
20 | import org.kohsuke.stapler.export.ExportedBean;
21 |
22 | @ExportedBean(defaultVisibility = AbstractItem.VISIBILITY)
23 | public abstract class GenericPipeline extends AbstractItem {
24 |
25 | public GenericPipeline(String name) {
26 | super(name);
27 | }
28 |
29 | public abstract long getLastActivity();
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/test/FakeRepositoryBrowserSCM.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.test;
19 |
20 | import hudson.scm.RepositoryBrowser;
21 | import org.jvnet.hudson.test.FakeChangeLogSCM;
22 |
23 | public class FakeRepositoryBrowserSCM extends FakeChangeLogSCM {
24 |
25 | @Override
26 | public RepositoryBrowser> getBrowser() {
27 | return new FakeRepositoryBrowser();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/domain/status/StatusFactoryTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain.status;
19 |
20 | import org.junit.Test;
21 | import se.diabol.jenkins.pipeline.test.TestUtil;
22 |
23 | public class StatusFactoryTest {
24 |
25 | @Test
26 | public void testValidUtilClass() throws Exception {
27 | TestUtil.assertUtilityClassWellDefined(StatusFactory.class);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/util/PipelineUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.util;
19 |
20 | import java.util.Random;
21 |
22 | public final class PipelineUtils {
23 |
24 | private static final Random RANDOM = new Random(System.currentTimeMillis());
25 |
26 | private PipelineUtils() {
27 | }
28 |
29 | public static long getRandom() {
30 | return RANDOM.nextLong();
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/test/MeanFakeRepositoryBrowserSCM.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.test;
19 |
20 | import hudson.scm.RepositoryBrowser;
21 | import org.jvnet.hudson.test.FakeChangeLogSCM;
22 |
23 | public class MeanFakeRepositoryBrowserSCM extends FakeChangeLogSCM {
24 | @Override
25 | public RepositoryBrowser> getBrowser() {
26 | return new MeanFakeRepositoryBrowser();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/workflow/step/TaskStepExecutionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.workflow.step;
19 |
20 | import org.junit.Test;
21 |
22 | public class TaskStepExecutionTest {
23 |
24 | @Test
25 | public void stopShouldNotThrowException() throws Exception {
26 | TaskStepExecution execution = new TaskStepExecution();
27 | execution.stop(new IllegalStateException("Test provoked exception"));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/workflow/model/Progress.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.workflow.model;
19 |
20 | import static java.lang.Math.round;
21 |
22 | public class Progress {
23 |
24 | private Progress() {
25 | }
26 |
27 | static int calculate(long timestampFromBuild, long estimatedDuration) {
28 | return (int) round(100.0d
29 | * (System.currentTimeMillis() - timestampFromBuild)
30 | / estimatedDuration);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/trigger/ManualTrigger.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.trigger;
19 |
20 | import hudson.model.AbstractProject;
21 | import hudson.model.ItemGroup;
22 | import hudson.model.TopLevelItem;
23 |
24 | public interface ManualTrigger {
25 | void triggerManual(AbstractProject,?> project, AbstractProject,?> upstream,
26 | String buildId, ItemGroup extends TopLevelItem> itemGroup) throws TriggerException;
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/resources/se/diabol/jenkins/pipeline/portlet/DeliveryPipelineViewPortlet/config.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.portlet.DeliveryPipelineViewPortlet
19 |
20 | f = namespace(lib.FormTagLib)
21 | t = namespace("/lib/hudson")
22 |
23 |
24 | f.entry(field:"name", title: "Name") {
25 | f.textbox()
26 | }
27 |
28 | f.entry(field:"initialJob", title: "Initial Job") {
29 | f.textbox()
30 | }
31 |
32 | f.entry(field:"finalJob", title: "Final Job (optional)") {
33 | f.textbox()
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/domain/Edge.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain;
19 |
20 | public class Edge {
21 |
22 | private final Stage source;
23 | private final Stage target;
24 |
25 | public Edge(Stage source, Stage target) {
26 | this.source = source;
27 | this.target = target;
28 | }
29 |
30 | public Stage getSource() {
31 | return source;
32 | }
33 |
34 | public Stage getTarget() {
35 | return target;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/functionaltest/ConfigureJobPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.functionaltest;
19 |
20 | import org.openqa.selenium.By;
21 | import org.openqa.selenium.WebDriver;
22 |
23 | public class ConfigureJobPage {
24 |
25 | private WebDriver webDriver;
26 |
27 | public ConfigureJobPage(WebDriver webDriver) {
28 | this.webDriver = webDriver;
29 | }
30 |
31 | public void submit() {
32 | webDriver.findElement(By.xpath("//*[@id=\"yui-gen32-button\"]")).click();
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/core/TimestampFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.core;
19 |
20 | import java.text.DateFormat;
21 | import java.text.SimpleDateFormat;
22 | import java.util.Date;
23 |
24 | public final class TimestampFormat {
25 |
26 | private static final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
27 |
28 | private TimestampFormat() {
29 | }
30 |
31 | public static String formatTimestamp(long timestamp) {
32 | return DATE_TIME_FORMAT.format(new Date(timestamp));
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/sort/BuildStartTimeComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.sort;
19 |
20 | import hudson.model.AbstractBuild;
21 |
22 | import java.util.Comparator;
23 |
24 | public final class BuildStartTimeComparator implements Comparator {
25 |
26 | @Override
27 | public int compare(AbstractBuild build1, AbstractBuild build2) {
28 | return compare(build2.getStartTimeInMillis(), build1.getStartTimeInMillis());
29 | }
30 |
31 | protected int compare(long first, long second) {
32 | return Long.compare(first, second);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/workflow/step/TaskFinishedAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.workflow.step;
19 |
20 | import hudson.model.InvisibleAction;
21 | import org.jenkinsci.plugins.workflow.actions.PersistentAction;
22 |
23 | import java.io.Serializable;
24 |
25 | public class TaskFinishedAction extends InvisibleAction implements PersistentAction, Serializable {
26 |
27 | private final Long finishedTime;
28 |
29 | public TaskFinishedAction(Long finishedTime) {
30 | this.finishedTime = finishedTime;
31 | }
32 |
33 | public Long getFinishedTime() {
34 | return finishedTime;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/resolver/ProjectRelationshipResolver.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.resolver;
19 |
20 | import hudson.Extension;
21 | import hudson.model.AbstractProject;
22 | import se.diabol.jenkins.pipeline.RelationshipResolver;
23 |
24 | import java.util.List;
25 |
26 | @Extension(ordinal = 100)
27 | @SuppressWarnings("UnusedDeclaration")
28 | public class ProjectRelationshipResolver extends RelationshipResolver {
29 |
30 | @Override
31 | public List getDownstreamProjects(AbstractProject, ?> project) {
32 | return project.getDownstreamProjects();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/test/MeanFakeRepositoryBrowser.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.test;
19 |
20 | import hudson.scm.RepositoryBrowser;
21 | import org.jvnet.hudson.test.FakeChangeLogSCM;
22 |
23 | import java.io.IOException;
24 | import java.net.URL;
25 |
26 | public class MeanFakeRepositoryBrowser extends RepositoryBrowser {
27 | private static final long serialVersionUID = 996026414850737194L;
28 |
29 | @Override
30 | public URL getChangeSetLink(FakeChangeLogSCM.EntryImpl changeSet) throws IOException {
31 | throw new IOException("I can get changeset link");
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/test/FakeRepositoryBrowser.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.test;
19 |
20 | import hudson.scm.RepositoryBrowser;
21 | import org.jvnet.hudson.test.FakeChangeLogSCM;
22 |
23 | import java.io.IOException;
24 | import java.net.URL;
25 |
26 | public class FakeRepositoryBrowser extends RepositoryBrowser {
27 |
28 | private static final long serialVersionUID = -5144842224743489576L;
29 |
30 | @Override
31 | public URL getChangeSetLink(FakeChangeLogSCM.EntryImpl changeSet) throws IOException {
32 | return new URL("http://somewhere.com/" + changeSet.getAuthor().getDisplayName());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/core/AbstractItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.core;
19 |
20 | import org.kohsuke.stapler.export.Exported;
21 | import org.kohsuke.stapler.export.ExportedBean;
22 |
23 | /**
24 | * This is the common abstraction for all the entities that makes a pipeline.
25 | */
26 | @ExportedBean(defaultVisibility = AbstractItem.VISIBILITY)
27 | public abstract class AbstractItem {
28 | private final String name;
29 |
30 | public static final int VISIBILITY = 100;
31 |
32 | protected AbstractItem(String name) {
33 | this.name = name;
34 | }
35 |
36 | @Exported
37 | public String getName() {
38 | return name;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/resources/se/diabol/jenkins/pipeline/DeliveryPipelineView/configure.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/main/resources/se/diabol/jenkins/workflow/WorkflowPipelineView/configure.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/domain/EdgeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain;
19 |
20 | import static org.junit.Assert.assertEquals;
21 |
22 | import org.junit.Test;
23 |
24 | import se.diabol.jenkins.pipeline.domain.task.Task;
25 |
26 | import java.util.Collections;
27 |
28 | public class EdgeTest {
29 |
30 | @Test
31 | public void testGetSet() {
32 | Stage stageA = new Stage("A", Collections.emptyList());
33 | Stage stageB = new Stage("B", Collections.emptyList());
34 |
35 | Edge edge = new Edge(stageA, stageB);
36 |
37 | assertEquals(edge.getSource(), stageA);
38 | assertEquals(edge.getTarget(), stageB);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/util/FullScreen.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.util;
19 |
20 | import org.kohsuke.stapler.StaplerRequest;
21 |
22 | public class FullScreen {
23 |
24 | public static boolean isFullScreenRequest(StaplerRequest request) {
25 | return request != null && hasFullScreenParameter(request)
26 | && Boolean.parseBoolean(getFullScreenParameter(request));
27 | }
28 |
29 | static boolean hasFullScreenParameter(StaplerRequest request) {
30 | return getFullScreenParameter(request) != null;
31 | }
32 |
33 | static String getFullScreenParameter(StaplerRequest request) {
34 | return request.getParameter("fullscreen");
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/sort/BuildStartTimeComparatorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.sort;
19 |
20 | import org.junit.Test;
21 |
22 | import static org.junit.Assert.*;
23 |
24 | public class BuildStartTimeComparatorTest {
25 |
26 | @Test
27 | public void shouldCompareBuildTimes() throws Exception {
28 | long first = 10L;
29 | long second = 20L;
30 | assertTrue(new BuildStartTimeComparator().compare(first, second) < 0);
31 |
32 | first = 30L;
33 | assertTrue(new BuildStartTimeComparator().compare(first, second) > 0);
34 |
35 | first = second;
36 | assertTrue(new BuildStartTimeComparator().compare(first, second) == 0);
37 | }
38 |
39 | }
--------------------------------------------------------------------------------
/settings.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 | org.jenkins-ci.tools
7 |
8 |
9 |
10 |
11 |
12 | jenkins
13 |
14 | true
15 |
16 |
17 |
18 | repo.jenkins-ci.org
19 | http://repo.jenkins-ci.org/public/
20 |
21 |
22 |
23 |
24 | repo.jenkins-ci.org
25 | http://repo.jenkins-ci.org/public/
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | repo.jenkins-ci.org
34 | http://repo.jenkins-ci.org/public/
35 | m.g.o-public
36 |
37 |
38 |
39 |
40 |
41 | maven.jenkins-ci.org
42 | ${env.JENKINSCI_USERNAME}
43 | ${env.JENKINSCI_PASSWORD}
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -x
3 | set -e
4 | if [ $# -eq 2 ]
5 | then
6 | branch=$1
7 | tag=$2
8 | else
9 | echo "Incorrect number of arguments"
10 | echo "Usage: release.sh "
11 | fi
12 |
13 | if [[ -n "$tag" ]] && [[ $tag =~ ^release-.* ]]; then
14 | version=`echo $tag | sed -n 's/release-\(.\)/\1/p'`
15 | head=`git rev-parse HEAD`
16 | commit=`git rev-list -n 1 $tag`
17 | if [[ "$head" == "$commit" ]]; then
18 | # prepare the ssh key
19 | openssl aes-256-cbc -K $encrypted_308f5ca9ca59_key -iv $encrypted_308f5ca9ca59_iv -in travis_deploy_key.enc -out travis_deploy_key -d
20 | chmod 600 travis_deploy_key
21 | eval `ssh-agent -s`
22 | ssh-add travis_deploy_key
23 |
24 | # prepare the repo
25 | git config user.name "diabolbuilder"
26 | git config user.email "info@diabol.se"
27 | git config --global push.default simple
28 | remote=`git config remote.origin.url | sed -n 's/https:\/\/github.com\/\(.*\)/git@github.com:\1/p'`
29 | git remote remove origin
30 | git remote add origin $remote
31 | git fetch
32 | git checkout -qf $branch
33 |
34 | # do the release
35 | mvn --settings settings.xml --batch-mode -DreleaseVersion=$version -Dwebdriver.chrome.driver=/usr/local/share/chromedriver -Darguments="-DskipTests=true" -DskipTests=true -DscmCommentPrefix="[maven-release-plugin][skip ci]" release:prepare release:perform
36 | else
37 | echo "Tag $tag does not point to $branch/head, aborting release"
38 | exit 1
39 | fi
40 | fi
41 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/domain/results/Result.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain.results;
19 |
20 | import org.kohsuke.stapler.export.Exported;
21 | import org.kohsuke.stapler.export.ExportedBean;
22 | import se.diabol.jenkins.core.AbstractItem;
23 |
24 | @ExportedBean(defaultVisibility = AbstractItem.VISIBILITY)
25 | public class Result {
26 |
27 | protected final String name;
28 | protected final String url;
29 |
30 | public Result(String name, String url) {
31 | this.name = name;
32 | this.url = url;
33 | }
34 |
35 | @Exported
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | @Exported
41 | public String getUrl() {
42 | return url;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: required
2 | language: java
3 | env:
4 | global:
5 | - JENKINSCI_USERNAME=diabol_jenkins
6 | - secure: "R3Wz/PgUYQqelwxXu+mMkHHzpLaFTxWmj6m+fOxnlJ85njJXOf/4jrMwMMLlvUM3DgZ+dJp8nANNxUPkOBIBLfbSNWGZTsLEJkGu+hEtBKCZhHLLXfIYhVc8tVFgEvfQo4QP+LXk63COfaIlE45cD8NIqFzebbMeN9K/MCOAIuw="
7 | jdk:
8 | - openjdk8
9 | notifications:
10 | slack:
11 | secure: phVNsiDfu5nDM7okqhGgX1Qhh3Sawqy5X3p5bgDarh9RX82V2OAebyiiKiw6aNGyDCoD0ElMHmz7tbdBODsR3muWyoQ5EJBsDgNv1NM9dhkdeIQ/182bF7EBFciPW5SYjl0+dOkIeMn9DHdg8i0RVxwjy6GjJX2r/6oUmYxExQk=
12 | before_install:
13 | - "export DISPLAY=:99.0"
14 | - "sed 's/localhost.localdomain localhost/localhost localhost.localdomain/' /etc/hosts > /tmp/etchostsfile && cat /tmp/etchostsfile | sudo tee /etc/hosts"
15 | - echo "MAVEN_OPTS='-Xmx2g -XX:MaxPermSize=1024m'" > ~/.mavenrc
16 | - wget -N http://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip -P ~/
17 | - unzip ~/chromedriver_linux64.zip -d ~/
18 | - rm ~/chromedriver_linux64.zip
19 | - sudo mv -f ~/chromedriver /usr/local/share/
20 | - sudo chmod +x /usr/local/share/chromedriver
21 | script:
22 | - "if [[ -z $TRAVIS_TAG ]]; then mvn --batch-mode -Dwebdriver.chrome.driver=/usr/local/share/chromedriver install; fi"
23 | - "if [[ -n $TRAVIS_TAG ]]; then ./release.sh master $TRAVIS_TAG; fi"
24 | services:
25 | - xvfb
26 | cache:
27 | directories:
28 | - $HOME/.m2
29 | after_success:
30 | - mvn jacoco:report coveralls:report
31 | - bash <(curl -s https://codecov.io/bash)
32 | addons:
33 | chrome: stable
34 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/functionaltest/SeleniumUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.functionaltest;
19 |
20 | import org.openqa.selenium.By;
21 | import org.openqa.selenium.WebDriver;
22 | import org.openqa.selenium.WebElement;
23 | import org.openqa.selenium.support.ui.WebDriverWait;
24 |
25 | import javax.annotation.Nullable;
26 |
27 | public class SeleniumUtil {
28 | public static WebElement waitForElement(WebDriver driver, String id) {
29 |
30 | return new WebDriverWait(driver, 30).until(
31 | new com.google.common.base.Function() {
32 | @Nullable
33 | @Override
34 | public WebElement apply(@Nullable WebDriver webDriver) {
35 | return webDriver.findElement(By.id(id));
36 | }
37 | });
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/trigger/ManualTriggerResolver.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.trigger;
19 |
20 | import hudson.ExtensionPoint;
21 | import hudson.model.AbstractProject;
22 | import se.diabol.jenkins.pipeline.util.JenkinsUtil;
23 |
24 | import java.util.List;
25 |
26 | public abstract class ManualTriggerResolver implements ExtensionPoint {
27 |
28 | public abstract ManualTrigger getManualTrigger(AbstractProject, ?> project, AbstractProject, ?> downstream);
29 |
30 | public abstract boolean isManualTrigger(AbstractProject, ?> project);
31 |
32 | public abstract List getUpstreamManualTriggered(AbstractProject, ?> project);
33 |
34 | public static List all() {
35 | return JenkinsUtil.getInstance().getExtensionList(ManualTriggerResolver.class);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/trigger/ManualTriggerFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.trigger;
19 |
20 | import hudson.model.AbstractProject;
21 |
22 | import java.util.List;
23 | import javax.annotation.CheckForNull;
24 |
25 | public final class ManualTriggerFactory {
26 |
27 | private ManualTriggerFactory() {
28 | }
29 |
30 | @CheckForNull
31 | public static ManualTrigger getManualTrigger(AbstractProject, ?> project, AbstractProject, ?> downstream) {
32 | List resolvers = ManualTriggerResolver.all();
33 | for (ManualTriggerResolver resolver : resolvers) {
34 | ManualTrigger trigger = resolver.getManualTrigger(project, downstream);
35 | if (trigger != null) {
36 | return trigger;
37 | }
38 | }
39 | return null;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/resolver/GitCauseResolver.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.resolver;
19 |
20 | import hudson.Extension;
21 | import hudson.model.Cause;
22 | import hudson.plugins.git.GitStatus;
23 | import se.diabol.jenkins.pipeline.CauseResolver;
24 | import se.diabol.jenkins.pipeline.domain.TriggerCause;
25 |
26 | @Extension(optional = true)
27 | public class GitCauseResolver extends CauseResolver {
28 |
29 | // Force a classloading error plugin isn't available
30 | @SuppressWarnings("UnusedDeclaration")
31 | public static final Class CLASS = GitStatus.CommitHookCause.class;
32 |
33 | @Override
34 | public TriggerCause resolveCause(Cause cause) {
35 | if (cause instanceof GitStatus.CommitHookCause) {
36 | return new TriggerCause(TriggerCause.TYPE_SCM, "SCM");
37 | }
38 | return null;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/PipelineVersionBuildVariableContributor.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline;
19 |
20 | import hudson.Extension;
21 | import hudson.model.AbstractBuild;
22 | import hudson.model.BuildVariableContributor;
23 | import se.diabol.jenkins.pipeline.PipelineVersionContributor.PipelineVersionAction;
24 |
25 | import java.util.Map;
26 |
27 | @Extension
28 | public class PipelineVersionBuildVariableContributor extends BuildVariableContributor {
29 | @Override
30 | public void buildVariablesFor(AbstractBuild build, Map variablesOut) {
31 | PipelineVersionAction pipelineVersionAction = build.getAction(PipelineVersionAction.class);
32 |
33 | if (pipelineVersionAction != null) {
34 | variablesOut.put(PipelineVersionContributor.VERSION_PARAMETER, pipelineVersionAction.getVersion());
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/domain/status/Status.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain.status;
19 |
20 | import org.kohsuke.stapler.export.ExportedBean;
21 | import se.diabol.jenkins.pipeline.domain.status.promotion.PromotionStatus;
22 |
23 | import java.util.List;
24 |
25 | @ExportedBean
26 | public interface Status {
27 |
28 | StatusType getType();
29 |
30 | boolean isIdle();
31 |
32 | boolean isQueued();
33 |
34 | boolean isRunning();
35 |
36 | boolean isSuccess();
37 |
38 | boolean isFailed();
39 |
40 | boolean isUnstable();
41 |
42 | boolean isCancelled();
43 |
44 | boolean isDisabled();
45 |
46 | boolean isNotBuilt();
47 |
48 | long getLastActivity();
49 |
50 | String getTimestamp();
51 |
52 | long getDuration();
53 |
54 | boolean isPromoted();
55 |
56 | List getPromotions();
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/domain/Route.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain;
19 |
20 | import se.diabol.jenkins.pipeline.domain.task.Task;
21 |
22 | import java.util.ArrayList;
23 | import java.util.List;
24 |
25 | /**
26 | * A possible route in the pipeline, comprised of tasks.
27 | */
28 | public class Route {
29 |
30 | private List tasks = new ArrayList<>();
31 |
32 | public List getTasks() {
33 | return tasks;
34 | }
35 |
36 | public void setTasks(List tasks) {
37 | this.tasks = tasks;
38 | }
39 |
40 | public long getTotalBuildTime() {
41 | long totalBuildTime = 0;
42 | for (Task task: tasks) {
43 | totalBuildTime += task.getStatus().getDuration();
44 | }
45 | return totalBuildTime;
46 | }
47 |
48 | public void addTask(Task task) {
49 | tasks.add(task);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/examples/demo.yaml:
--------------------------------------------------------------------------------
1 | - job:
2 | name: 'demo-build'
3 | properties:
4 | - delivery-pipeline:
5 | stage: Build
6 | task: Build
7 | wrappers:
8 | - delivery-pipeline:
9 | version-template: 1.0.0-${BUILD_NUMBER}
10 | set-display-name: true
11 | publishers:
12 | - trigger:
13 | project: demo-deploy-CI
14 | - job:
15 | name: 'demo-deploy-CI'
16 | properties:
17 | - delivery-pipeline:
18 | stage: CI
19 | task: Deploy
20 | publishers:
21 | - trigger:
22 | project: demo-test-CI
23 |
24 | - job:
25 | name: 'demo-test-CI'
26 | properties:
27 | - delivery-pipeline:
28 | stage: CI
29 | task: Test
30 | publishers:
31 | - pipeline:
32 | project: demo-deploy-QA
33 |
34 | - job:
35 | name: 'demo-deploy-QA'
36 | properties:
37 | - delivery-pipeline:
38 | stage: QA
39 | task: Deploy
40 | publishers:
41 | - trigger:
42 | project: demo-test-QA
43 |
44 | - job:
45 | name: 'demo-test-QA'
46 | properties:
47 | - delivery-pipeline:
48 | stage: QA
49 | task: Test
50 | publishers:
51 | - pipeline:
52 | project: demo-deploy-PROD
53 |
54 | - job:
55 | name: 'demo-deploy-PROD'
56 | properties:
57 | - delivery-pipeline:
58 | stage: PROD
59 | task: Deploy
60 | publishers:
61 | - trigger:
62 | project: demo-test-PROD
63 |
64 | - job:
65 | name: 'demo-test-PROD'
66 | properties:
67 | - delivery-pipeline:
68 | stage: PROD
69 | task: Smoke Test
70 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/sort/NameComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.sort;
19 |
20 | import hudson.Extension;
21 | import se.diabol.jenkins.core.GenericComponent;
22 |
23 | import java.io.Serializable;
24 |
25 | public class NameComparator extends GenericComponentComparator implements Serializable {
26 |
27 | @Override
28 | public int compare(GenericComponent component1, GenericComponent component2) {
29 | return component1.getName().compareTo(component2.getName());
30 | }
31 |
32 | @Extension
33 | public static class DescriptorImpl extends ComponentComparatorDescriptor {
34 | @Override
35 | public String getDisplayName() {
36 | return "Sort by title";
37 | }
38 |
39 | @Override
40 | public GenericComponentComparator createInstance() {
41 | return new NameComparator();
42 | }
43 | }
44 |
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/domain/status/Running.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain.status;
19 |
20 | import org.kohsuke.stapler.export.Exported;
21 | import org.kohsuke.stapler.export.ExportedBean;
22 | import se.diabol.jenkins.core.AbstractItem;
23 |
24 | @ExportedBean(defaultVisibility = AbstractItem.VISIBILITY)
25 | public class Running extends SimpleStatus {
26 | private final int percentage;
27 |
28 | Running(int percentage, long lastActivity, long duration) {
29 | super(StatusType.RUNNING, lastActivity, duration);
30 | this.percentage = percentage;
31 | }
32 |
33 | @Exported
34 | public int getPercentage() {
35 | return percentage;
36 | }
37 |
38 | @Override
39 | public boolean isRunning() {
40 | return true;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return "RUNNING " + percentage + "%";
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/examples/show-test-results.yaml:
--------------------------------------------------------------------------------
1 | - job:
2 | name: 'example-str-build'
3 | properties:
4 | - delivery-pipeline:
5 | stage: 'Commit stage'
6 | task: 'Build and unit test'
7 | wrappers:
8 | - delivery-pipeline:
9 | version-template: 1.0.0-${BUILD_NUMBER}
10 | set-display-name: true
11 | builders:
12 | - shell: |
13 | #!/bin/bash
14 | echo "Compile"
15 |
16 | # Mimic test results
17 | mkdir -p target/test-reports
18 | echo "
19 |
20 |
21 |
22 | Details about the test failure
23 |
24 | " > target/test-reports/junit.xml
25 |
26 | sleep 1
27 | publishers:
28 | - trigger-parameterized-builds:
29 | - project: "example-str-test"
30 | fail-on-missing: false
31 | predefined-parameters: foo=bar
32 |
33 | - job:
34 | name: 'example-str-test'
35 | properties:
36 | - delivery-pipeline:
37 | stage: 'Test'
38 | task: 'Run integration tests'
39 | publishers:
40 | - trigger-parameterized-builds:
41 | - project: 'example-str-deploy'
42 | fail-on-missing: false
43 | predefined-parameters: foo=bar
44 |
45 | - job:
46 | name: 'example-str-deploy'
47 | properties:
48 | - delivery-pipeline:
49 | stage: 'Deploy'
50 | task: 'Deploy to production'
51 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/core/GenericComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.core;
19 |
20 | import org.kohsuke.stapler.export.Exported;
21 | import org.kohsuke.stapler.export.ExportedBean;
22 |
23 | import java.util.List;
24 |
25 | @ExportedBean(defaultVisibility = AbstractItem.VISIBILITY)
26 | public abstract class GenericComponent extends AbstractItem {
27 |
28 | public GenericComponent(String name) {
29 | super(name);
30 | }
31 |
32 | @Exported
33 | public long getLastActivity() {
34 | long result = 0;
35 | if (getPipelines() != null) {
36 | for (GenericPipeline pipeline : getPipelines()) {
37 | long lastActivity = pipeline.getLastActivity();
38 | if (lastActivity > result) {
39 | result = lastActivity;
40 | }
41 | }
42 | }
43 | return result;
44 | }
45 |
46 | @Exported
47 | public abstract List extends GenericPipeline> getPipelines();
48 | }
49 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/resolver/GitCauseResolverTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.resolver;
19 |
20 | import static org.junit.Assert.assertEquals;
21 | import static org.junit.Assert.assertNotNull;
22 | import static org.junit.Assert.assertNull;
23 |
24 | import hudson.model.Cause;
25 | import hudson.plugins.git.GitStatus;
26 | import org.junit.Test;
27 | import se.diabol.jenkins.pipeline.domain.TriggerCause;
28 |
29 | public class GitCauseResolverTest {
30 |
31 | @Test
32 | public void withCorrectCause() {
33 | TriggerCause cause = new GitCauseResolver().resolveCause(new GitStatus.CommitHookCause("sha1"));
34 | assertNotNull(cause);
35 | assertEquals(TriggerCause.TYPE_SCM, cause.getType());
36 | assertEquals("SCM", cause.getDescription());
37 | }
38 |
39 | @Test
40 | public void withUnknownCause() {
41 | assertNull(new GitCauseResolver().resolveCause(new Cause.RemoteCause("hostname", "note")));
42 | }
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/examples/JENKINS-45738-declarative-pipeline-with-task-closures.txt:
--------------------------------------------------------------------------------
1 | pipeline {
2 | agent any
3 | options {
4 | ansiColor('xterm')
5 | buildDiscarder(logRotator(numToKeepStr: '20'))
6 | timeout(time: 30, unit: 'MINUTES')
7 | timestamps()
8 | }
9 | stages {
10 | stage('Commit stage') {
11 | steps {
12 | task('Compile and package') {
13 | echo 'Building...'
14 | sleep 2
15 | echo 'Successfully built project!'
16 | }
17 |
18 | task('Upload artifacts') {
19 | sleep 3
20 | echo 'Successfully uploaded artifacts!'
21 | }
22 | }
23 | }
24 | stage('Test stage') {
25 | steps {
26 | task('Run component tests') {
27 | echo 'Running tests...'
28 | sleep 4
29 | echo 'Component tests finished!'
30 | }
31 |
32 | task('Run integration tests') {
33 | sleep 5
34 | echo 'Integration tests finished'
35 | }
36 | }
37 | }
38 | stage('Deploy') {
39 | steps {
40 | task('Deploy to UAT') {
41 | echo 'Deploying to UAT...'
42 | sleep 4
43 | echo 'Successfully deployed to UAT'
44 | }
45 |
46 | task('Deploy to production') {
47 | echo 'Deploying to production...'
48 | sleep 4
49 | echo 'Deployed to production!'
50 | }
51 | }
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/sort/GenericComponentComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.sort;
19 |
20 | import hudson.DescriptorExtensionList;
21 | import hudson.ExtensionPoint;
22 | import hudson.model.Describable;
23 | import hudson.model.Descriptor;
24 | import se.diabol.jenkins.core.GenericComponent;
25 | import se.diabol.jenkins.pipeline.util.JenkinsUtil;
26 |
27 | import java.util.Comparator;
28 |
29 | public abstract class GenericComponentComparator implements Comparator,
30 | ExtensionPoint,
31 | Describable {
32 |
33 | @Override
34 | public Descriptor getDescriptor() {
35 | return (ComponentComparatorDescriptor) JenkinsUtil.getInstance().getDescriptor(getClass());
36 | }
37 |
38 | public static DescriptorExtensionList all() {
39 | return JenkinsUtil.getInstance().getDescriptorList(GenericComponentComparator.class);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/sort/NameComparatorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.sort;
19 |
20 | import static org.junit.Assert.assertEquals;
21 |
22 | import org.junit.Test;
23 | import se.diabol.jenkins.pipeline.domain.Component;
24 |
25 | import java.util.ArrayList;
26 | import java.util.Collections;
27 | import java.util.List;
28 |
29 | public class NameComparatorTest {
30 |
31 | private static final boolean PAGING_DISABLED = false;
32 |
33 | @Test
34 | public void testCompare() {
35 | Component componentB = new Component("B", "B", "job/A", false, 3, PAGING_DISABLED, 1);
36 | Component componentA = new Component("A", "A", "job/B", false, 3, PAGING_DISABLED, 2);
37 | List list = new ArrayList<>();
38 | list.add(componentB);
39 | list.add(componentA);
40 | list.sort(new NameComparator.DescriptorImpl().createInstance());
41 | assertEquals(componentA, list.get(0));
42 | assertEquals(componentB, list.get(1));
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/portlet/DeliveryPipelineViewPortletTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.portlet;
19 |
20 | import static org.junit.Assert.assertEquals;
21 | import static org.junit.Assert.assertNotNull;
22 |
23 | import org.junit.Rule;
24 | import org.junit.Test;
25 | import org.junit.runner.RunWith;
26 | import org.jvnet.hudson.test.JenkinsRule;
27 | import org.jvnet.hudson.test.WithoutJenkins;
28 | import org.mockito.junit.MockitoJUnitRunner;
29 |
30 | import java.io.IOException;
31 |
32 | @RunWith(MockitoJUnitRunner.class)
33 | public class DeliveryPipelineViewPortletTest {
34 |
35 | @Rule
36 | public JenkinsRule jenkins = new JenkinsRule();
37 |
38 | @Test
39 | @WithoutJenkins
40 | public void testDefaults() throws IOException {
41 | DeliveryPipelineViewPortlet portlet = new DeliveryPipelineViewPortlet("PipelinePortlet","Build","Test");
42 | assertNotNull(portlet.getPortletId());
43 | assertEquals("Build", portlet.getInitialJob());
44 | assertEquals("Test", portlet.getFinalJob());
45 | assertEquals("PipelinePortlet", portlet.getName());
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/RelationshipResolver.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline;
19 |
20 | import hudson.ExtensionPoint;
21 | import hudson.model.AbstractProject;
22 | import se.diabol.jenkins.pipeline.util.JenkinsUtil;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * Defines an ExtensionPoint for resolving a projects downstream relationships.
28 | */
29 | public abstract class RelationshipResolver implements ExtensionPoint {
30 |
31 | /**
32 | * Returns the downstream projects for the given project.
33 | *
34 | * @param project the project which to resolve downstream dependencies for
35 | * @return the downstream projects for the given project.
36 | */
37 | public abstract List getDownstreamProjects(AbstractProject, ?> project);
38 |
39 | /**
40 | * Returns all loaded implementations of this extension point.
41 | *
42 | * @return all loaded implementations of this extension point.
43 | */
44 | public static List all() {
45 | return JenkinsUtil.getInstance().getExtensionList(RelationshipResolver.class);
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/sort/LatestActivityComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.sort;
19 |
20 | import hudson.Extension;
21 | import se.diabol.jenkins.core.GenericComponent;
22 |
23 | import java.io.Serializable;
24 |
25 | public class LatestActivityComparator extends GenericComponentComparator implements Serializable {
26 |
27 | @Override
28 | public int compare(GenericComponent component1, GenericComponent component2) {
29 | long component1LastActivity = component1 == null ? 0 : component1.getLastActivity();
30 | long component2LastActivity = component2 == null ? 0 : component2.getLastActivity();
31 | return Long.compare(component2LastActivity, component1LastActivity);
32 | }
33 |
34 | @Extension
35 | public static class DescriptorImpl extends ComponentComparatorDescriptor {
36 | @Override
37 | public String getDisplayName() {
38 | return "Sorting by last activity";
39 | }
40 |
41 | @Override
42 | public GenericComponentComparator createInstance() {
43 | return new LatestActivityComparator();
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/workflow/step/TaskStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.workflow.step;
19 |
20 | import org.junit.Test;
21 |
22 | import static org.hamcrest.core.Is.is;
23 | import static org.junit.Assert.*;
24 |
25 | public class TaskStepTest {
26 |
27 | @Test(expected = IllegalArgumentException.class)
28 | public void shouldThrowIllegalArgumentForNullNameInConstructor() {
29 | new TaskStep(null);
30 | }
31 |
32 | @Test(expected = IllegalArgumentException.class)
33 | public void shouldThrowIllegalArgumentForEmptyNameInConstructor() {
34 | new TaskStep("");
35 | }
36 |
37 | @Test
38 | public void constructorShouldTakeName() {
39 | String expectedName = "taskStep";
40 | TaskStep taskStep = new TaskStep(expectedName);
41 | assertThat(taskStep.name, is(expectedName));
42 | }
43 |
44 | @Test
45 | public void descriptorShouldReturnExpectedNames() {
46 | TaskStep.DescriptorImpl descriptor = new TaskStep.DescriptorImpl();
47 | assertThat(descriptor.getDisplayName(), is("Task"));
48 | assertThat(descriptor.getFunctionName(), is("task"));
49 | }
50 | }
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/PipelineVersionTokenMacro.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline;
19 |
20 | import hudson.Extension;
21 | import hudson.model.AbstractBuild;
22 | import hudson.model.TaskListener;
23 | import org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro;
24 | import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;
25 |
26 | @Extension
27 | @SuppressWarnings("UnusedDeclaration")
28 | public class PipelineVersionTokenMacro extends DataBoundTokenMacro {
29 |
30 | @Override
31 | public String evaluate(AbstractBuild, ?> context, TaskListener listener, String macroName)
32 | throws MacroEvaluationException {
33 | String version = PipelineVersionContributor.getVersion(context);
34 | if (version == null) {
35 | throw new MacroEvaluationException("Could not find " + PipelineVersionContributor.VERSION_PARAMETER
36 | + " parameter on this build!");
37 | }
38 | return version;
39 | }
40 |
41 | @Override
42 | public boolean acceptsMacroName(String macroName) {
43 | return PipelineVersionContributor.VERSION_PARAMETER.equals(macroName);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/PipelineEnvironmentContributor.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline;
19 |
20 | import hudson.Extension;
21 | import hudson.model.AbstractBuild;
22 | import hudson.model.Run;
23 | import hudson.model.TaskListener;
24 | import hudson.model.listeners.RunListener;
25 | import se.diabol.jenkins.pipeline.util.BuildUtil;
26 |
27 | @Extension
28 | @SuppressWarnings("UnusedDeclaration")
29 | public class PipelineEnvironmentContributor extends RunListener {
30 |
31 | @Override
32 | public void onStarted(Run run, TaskListener listener) {
33 | if (run instanceof AbstractBuild) {
34 | AbstractBuild build = (AbstractBuild) run;
35 | AbstractBuild upstreamBuild = BuildUtil.getUpstreamBuild(build);
36 | if (upstreamBuild != null) {
37 | String version = PipelineVersionContributor.getVersion(upstreamBuild);
38 | if (version != null) {
39 | PipelineVersionContributor.setVersion(build, version);
40 | listener.getLogger().println("Setting version to: " + version + " from upstream version");
41 | }
42 | }
43 | }
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/functionaltest/NewJobPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.functionaltest;
19 |
20 | import org.openqa.selenium.By;
21 | import org.openqa.selenium.WebDriver;
22 |
23 | public class NewJobPage {
24 |
25 | private WebDriver webDriver;
26 | private String baseUrl;
27 |
28 |
29 | public NewJobPage(WebDriver webDriver, String baseUrl) {
30 | this.webDriver = webDriver;
31 | this.baseUrl = baseUrl;
32 | }
33 |
34 | public NewJobPage open() {
35 | webDriver.get(baseUrl + "/newJob");
36 | SeleniumUtil.waitForElement(webDriver, "ok-button");
37 | return this;
38 | }
39 |
40 | public void setJobName(String name) {
41 | SeleniumUtil.waitForElement(webDriver, "ok-button");
42 | webDriver.findElement(By.xpath("//*[@id=\"name\"]")).sendKeys(name);
43 | }
44 |
45 | public void setFreeStyle() {
46 | webDriver.findElement(By.xpath("//*[@id=\"j-add-item-type-standalone-projects\"]/ul/li[1]")).click();
47 | }
48 |
49 | public ConfigureJobPage submit() {
50 | webDriver.findElement(By.id("ok-button")).click();
51 | return new ConfigureJobPage(webDriver);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/workflow/model/ProgressTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.workflow.model;
19 |
20 | import org.junit.Test;
21 |
22 | import static org.hamcrest.Matchers.greaterThan;
23 | import static org.hamcrest.Matchers.greaterThanOrEqualTo;
24 | import static org.hamcrest.Matchers.lessThan;
25 | import static org.junit.Assert.*;
26 |
27 | public class ProgressTest {
28 |
29 | @Test
30 | public void shouldCalculateProgressWhenHalfwayThroughEstimatedDuration() {
31 | long buildTimestamp = System.currentTimeMillis() - 10000L;
32 | long estimatedDuration = 20000L;
33 | int progress = Progress.calculate(buildTimestamp, estimatedDuration);
34 | assertThat(progress, greaterThanOrEqualTo(50));
35 | assertThat(progress, lessThan(60));
36 | }
37 |
38 | @Test
39 | public void shouldCalculateProgressWhenExceedingEstimatedDuration() {
40 | long buildTimestamp = System.currentTimeMillis() - 11000L;
41 | long estimatedDuration = 5000L;
42 | int progress = Progress.calculate(buildTimestamp, estimatedDuration);
43 | assertThat(progress, greaterThan(100));
44 | assertThat(progress, greaterThanOrEqualTo(200));
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/util/JenkinsUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.util;
19 |
20 | import jenkins.model.Jenkins;
21 |
22 | public final class JenkinsUtil {
23 |
24 | private JenkinsUtil() {
25 | }
26 |
27 | /**
28 | * Gets the Jenkins singleton.
29 | * @return the instance, or null if Jenkins has not been started, or was already shut down
30 | * @throws IllegalStateException {@link Jenkins} has not been started, or was already shut down
31 | */
32 | public static Jenkins getInstance() {
33 | Jenkins instance = Jenkins.getInstance();
34 | if (instance == null) {
35 | throw new IllegalStateException("Jenkins has not been started, or was already shut down");
36 | }
37 | return instance;
38 | }
39 |
40 | /**
41 | * Returns whether the specified plug-in is installed.
42 | *
43 | * @param shortName
44 | * the plug-in to check
45 | * @return true if the specified plug-in is installed,
46 | * false if not.
47 | */
48 | public static boolean isPluginInstalled(final String shortName) {
49 | return getInstance().getPlugin(shortName) != null;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/workflow/WorkflowApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.workflow;
19 |
20 | import com.cloudbees.workflow.rest.external.RunExt;
21 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
22 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
23 | import se.diabol.jenkins.pipeline.domain.PipelineException;
24 | import se.diabol.jenkins.workflow.api.Run;
25 |
26 | import java.util.ArrayList;
27 | import java.util.List;
28 |
29 | public class WorkflowApi {
30 |
31 | public WorkflowApi() {
32 | }
33 |
34 | public List getRunsFor(WorkflowJob job) {
35 | List runs = new ArrayList<>();
36 | for (WorkflowRun run : job.getBuilds()) {
37 | runs.add(new Run(RunExt.create(run)));
38 | }
39 | return runs;
40 | }
41 |
42 | public Run lastFinishedRunFor(WorkflowJob job) throws PipelineException {
43 | return lastFinishedRun(getRunsFor(job));
44 | }
45 |
46 | private Run lastFinishedRun(List runs) {
47 | for (Run run : runs) {
48 | if (!"IN_PROGRESS".equals(run.status) && !"PAUSED_PENDING_INPUT".equals(run.status)) {
49 | return run;
50 | }
51 | }
52 | return null;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/workflow/step/TaskStep.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.workflow.step;
19 |
20 | import hudson.Extension;
21 | import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
22 | import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
23 | import org.kohsuke.stapler.DataBoundConstructor;
24 |
25 | public class TaskStep extends AbstractStepImpl {
26 |
27 | public final String name;
28 |
29 | @DataBoundConstructor
30 | public TaskStep(String name) {
31 | if (name == null || name.isEmpty()) {
32 | throw new IllegalArgumentException("must specify name");
33 | }
34 | this.name = name;
35 | }
36 |
37 | @Extension
38 | public static final class DescriptorImpl extends AbstractStepDescriptorImpl {
39 |
40 | public DescriptorImpl() {
41 | super(TaskStepExecution.class);
42 | }
43 |
44 | @Override
45 | public String getFunctionName() {
46 | return "task";
47 | }
48 |
49 | @Override
50 | public String getDisplayName() {
51 | return "Task";
52 | }
53 |
54 | @Override
55 | public boolean takesImplicitBlockArgument() {
56 | return true;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/trigger/BPPManualTrigger.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.trigger;
19 |
20 | import au.com.centrumsystems.hudson.plugin.buildpipeline.extension.StandardBuildCard;
21 | import hudson.model.AbstractProject;
22 | import hudson.model.ItemGroup;
23 | import hudson.model.TopLevelItem;
24 |
25 | public class BPPManualTrigger implements ManualTrigger {
26 |
27 | @Override
28 | public void triggerManual(AbstractProject, ?> project, AbstractProject, ?> upstream, String buildId,
29 | ItemGroup extends TopLevelItem> itemGroup) throws TriggerException {
30 | StandardBuildCard buildCard = new StandardBuildCard();
31 |
32 | if (upstream != null && upstream.getBuild(buildId) != null) {
33 |
34 | try {
35 | buildCard.triggerManualBuild(itemGroup, Integer.parseInt(buildId),
36 | project.getRelativeNameFrom(itemGroup),
37 | upstream.getRelativeNameFrom(itemGroup));
38 | } catch (Exception e) {
39 | throw new TriggerException("Could not trigger", e);
40 | }
41 | } else {
42 | throw new TriggerException("Could not find build: " + buildId + " for project: " + upstream);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/resolver/SubProjectRelationshipResolver.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.resolver;
19 |
20 | import hudson.Extension;
21 | import hudson.Util;
22 | import hudson.model.AbstractProject;
23 | import hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig;
24 | import hudson.plugins.parameterizedtrigger.SubProjectsAction;
25 | import se.diabol.jenkins.pipeline.RelationshipResolver;
26 |
27 | import java.util.ArrayList;
28 | import java.util.List;
29 |
30 | /**
31 | * It looks for Parameterized Trigger Plugin builders for the current project.
32 | * They are for some reason not registered as a dependency in Jenkins.
33 | */
34 | @Extension(ordinal = 200)
35 | public class SubProjectRelationshipResolver extends RelationshipResolver {
36 |
37 | @Override
38 | public List getDownstreamProjects(AbstractProject, ?> project) {
39 | List result = new ArrayList<>();
40 | for (SubProjectsAction action : Util.filter(project.getActions(), SubProjectsAction.class)) {
41 | for (BlockableBuildTriggerConfig config : action.getConfigs()) {
42 | result.addAll(config.getProjectList(project.getParent(), null));
43 | }
44 | }
45 | return result;
46 | }
47 |
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/resources/se/diabol/jenkins/workflow/WorkflowPipelineView/configure-entries.jelly:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | ${instance.getDescription()}
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/domain/status/StatusTypeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain.status;
19 |
20 | import org.junit.Test;
21 |
22 | import static org.junit.Assert.assertEquals;
23 | import static org.junit.Assert.assertNotNull;
24 |
25 | public class StatusTypeTest {
26 |
27 | @Test
28 | public void testValueOf() {
29 | assertEquals(StatusType.CANCELLED, StatusType.valueOf("CANCELLED"));
30 | assertEquals(StatusType.DISABLED, StatusType.valueOf("DISABLED"));
31 | assertEquals(StatusType.FAILED, StatusType.valueOf("FAILED"));
32 | assertEquals(StatusType.IDLE, StatusType.valueOf("IDLE"));
33 | assertEquals(StatusType.QUEUED, StatusType.valueOf("QUEUED"));
34 | assertEquals(StatusType.RUNNING, StatusType.valueOf("RUNNING"));
35 | assertEquals(StatusType.SUCCESS, StatusType.valueOf("SUCCESS"));
36 | assertEquals(StatusType.UNSTABLE, StatusType.valueOf("UNSTABLE"));
37 | assertEquals(StatusType.NOT_BUILT, StatusType.valueOf("NOT_BUILT"));
38 | assertEquals(StatusType.PAUSED_PENDING_INPUT, StatusType.valueOf("PAUSED_PENDING_INPUT"));
39 | }
40 |
41 | @Test
42 | public void testValue() {
43 | StatusType[] values = StatusType.values();
44 | assertNotNull(values);
45 | assertEquals(10, values.length);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/examples/simple.yaml:
--------------------------------------------------------------------------------
1 | - job:
2 | name: 'simple-build'
3 | properties:
4 | - delivery-pipeline:
5 | stage: Build
6 | task: Build
7 | wrappers:
8 | - delivery-pipeline:
9 | version-template: 1.0.0-${BUILD_NUMBER}
10 | set-display-name: true
11 | publishers:
12 | - trigger-parameterized-builds:
13 | - project: "simple-deploy-CI"
14 | fail-on-missing: false
15 | predefined-parameters: foo=bar
16 | - job:
17 | name: 'simple-deploy-CI'
18 | properties:
19 | - delivery-pipeline:
20 | stage: CI
21 | task: Deploy
22 | publishers:
23 | - trigger-parameterized-builds:
24 | - project: "simple-test-CI"
25 | fail-on-missing: false
26 | predefined-parameters: foo=bar
27 |
28 | - job:
29 | name: 'simple-test-CI'
30 | properties:
31 | - delivery-pipeline:
32 | stage: CI
33 | task: Test
34 | publishers:
35 | - pipeline:
36 | project: simple-deploy-QA
37 |
38 | - job:
39 | name: 'simple-deploy-QA'
40 | properties:
41 | - delivery-pipeline:
42 | stage: QA
43 | task: Deploy
44 | publishers:
45 | - trigger-parameterized-builds:
46 | - project: "simple-test-QA"
47 | fail-on-missing: false
48 | predefined-parameters: foo=bar
49 |
50 | - job:
51 | name: 'simple-test-QA'
52 | properties:
53 | - delivery-pipeline:
54 | stage: QA
55 | task: Test
56 | publishers:
57 | - pipeline:
58 | project: "simple-deploy-PROD"
59 |
60 | - job:
61 | name: 'simple-deploy-PROD'
62 | properties:
63 | - delivery-pipeline:
64 | stage: PROD
65 | task: Deploy
66 | publishers:
67 | - trigger-parameterized-builds:
68 | - project: "simple-test-PROD"
69 | fail-on-missing: false
70 | predefined-parameters: foo=bar
71 |
72 | - job:
73 | name: 'simple-test-PROD'
74 | properties:
75 | - delivery-pipeline:
76 | stage: PROD
77 | task: Smoke Test
78 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/EnvVersionTokenMacro.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline;
19 |
20 | import hudson.Extension;
21 | import hudson.model.AbstractBuild;
22 | import hudson.model.TaskListener;
23 | import org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro;
24 |
25 | import java.io.IOException;
26 | import java.util.Map;
27 |
28 | @Extension(optional = true)
29 | public class EnvVersionTokenMacro extends DataBoundTokenMacro {
30 |
31 | private static final String NAME = "ENV_VERSION";
32 | public static final Class clazz = DataBoundTokenMacro.class;
33 |
34 | @DataBoundTokenMacro.Parameter(required = false)
35 | public boolean stripSnapshot = false;
36 |
37 | @Override
38 | public String evaluate(AbstractBuild, ?> context, TaskListener listener, String macroName)
39 | throws IOException, InterruptedException {
40 | Map env = context.getEnvironment(listener);
41 | if (env.containsKey(NAME)) {
42 | if (stripSnapshot) {
43 | String version = env.get(NAME);
44 | return version.replace("-SNAPSHOT", "");
45 | } else {
46 | return env.get(NAME);
47 | }
48 | }
49 | return "";
50 | }
51 |
52 | @Override
53 | public boolean acceptsMacroName(String macroName) {
54 | return NAME.equals(macroName);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/util/JenkinsUtilTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.util;
19 |
20 | import static org.junit.Assert.fail;
21 |
22 | import jenkins.model.Jenkins;
23 | import org.junit.Test;
24 | import org.junit.runner.RunWith;
25 | import org.powermock.api.mockito.PowerMockito;
26 | import org.powermock.core.classloader.annotations.PowerMockIgnore;
27 | import org.powermock.core.classloader.annotations.PrepareForTest;
28 | import org.powermock.modules.junit4.PowerMockRunner;
29 | import se.diabol.jenkins.pipeline.test.TestUtil;
30 |
31 | @RunWith(PowerMockRunner.class)
32 | @PowerMockIgnore({"com.thoughtworks.xstream.*"})
33 | @PrepareForTest(Jenkins.class)
34 | public class JenkinsUtilTest {
35 |
36 | @Test
37 | public void testValidUtilClass() throws Exception {
38 | TestUtil.assertUtilityClassWellDefined(JenkinsUtil.class);
39 | }
40 |
41 | @Test(expected = IllegalStateException.class)
42 | public void getInstanceJenkinsReturnsNull() throws Exception {
43 | PowerMockito.mockStatic(Jenkins.class);
44 | PowerMockito.when(Jenkins.getInstance()).thenReturn(null);
45 | JenkinsUtil.getInstance();
46 | }
47 |
48 | @Test(expected = IllegalStateException.class)
49 | public void testIsPluginInstalledNoJenkins() {
50 | JenkinsUtil.isPluginInstalled("analysis-core");
51 | fail("Should throw exception");
52 | }
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/workflow/model/WorkflowStatus.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.workflow.model;
19 |
20 | import se.diabol.jenkins.pipeline.domain.status.SimpleStatus;
21 | import se.diabol.jenkins.pipeline.domain.status.StatusType;
22 | import se.diabol.jenkins.workflow.api.Stage;
23 |
24 | public class WorkflowStatus extends SimpleStatus {
25 |
26 | public WorkflowStatus(StatusType type, long lastActivity, long duration) {
27 | super(type, lastActivity, duration);
28 | }
29 |
30 | public static WorkflowStatus of(Stage stage) {
31 | return new WorkflowStatus(
32 | statusType(stage), stage.startTimeMillis.getMillis() + stage.durationMillis, stage.durationMillis);
33 | }
34 |
35 | static StatusType statusType(Stage currentStage) {
36 | StatusType statusType;
37 | if (currentStage == null || currentStage.status == null) {
38 | return StatusType.NOT_BUILT;
39 | } else if (currentStage.status.equals("IN_PROGRESS")) {
40 | statusType = StatusType.RUNNING;
41 | } else if (currentStage.status.equals("ABORTED")) {
42 | statusType = StatusType.CANCELLED;
43 | } else if (currentStage.status.equals("NOT_EXECUTED")) {
44 | statusType = StatusType.NOT_BUILT;
45 | } else {
46 | statusType = StatusType.valueOf(currentStage.status);
47 | }
48 | return statusType;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/core/GenericComponentTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.core;
19 |
20 | import org.junit.Test;
21 |
22 | import java.util.Arrays;
23 | import java.util.List;
24 |
25 | import static org.hamcrest.core.Is.is;
26 | import static org.junit.Assert.assertThat;
27 |
28 | public class GenericComponentTest {
29 |
30 | @Test
31 | public void shouldGetLastActivity() {
32 | final long latestActivity = System.currentTimeMillis();
33 |
34 | GenericPipeline first = new GenericPipeline("") {
35 | @Override
36 | public long getLastActivity() {
37 | return 1000;
38 | }
39 | };
40 |
41 | GenericPipeline second = new GenericPipeline("") {
42 | @Override
43 | public long getLastActivity() {
44 | return 2000;
45 | }
46 | };
47 |
48 | GenericPipeline third = new GenericPipeline("") {
49 | @Override
50 | public long getLastActivity() {
51 | return latestActivity;
52 | }
53 | };
54 |
55 | GenericComponent component = new GenericComponent("component") {
56 | @Override
57 | public List extends GenericPipeline> getPipelines() {
58 | return Arrays.asList(first, second, third);
59 | }
60 | };
61 |
62 | assertThat(component.getLastActivity(), is(latestActivity));
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/domain/status/promotion/AbstractPromotionStatusProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain.status.promotion;
19 |
20 | import hudson.ExtensionList;
21 | import hudson.ExtensionPoint;
22 | import hudson.model.AbstractBuild;
23 | import jenkins.model.Jenkins;
24 |
25 | import java.util.List;
26 |
27 | public abstract class AbstractPromotionStatusProvider implements ExtensionPoint {
28 |
29 | private static JenkinsInstanceProvider jenkinsInstanceProvider = new JenkinsInstanceProvider();
30 |
31 | public abstract boolean isBuildPromoted(AbstractBuild, ?> build);
32 |
33 | public abstract List getPromotionStatusList(AbstractBuild, ?> build);
34 |
35 | public static ExtensionList all() {
36 | return AbstractPromotionStatusProvider.jenkinsInstanceProvider.getJenkinsInstance()
37 | .getExtensionList(AbstractPromotionStatusProvider.class);
38 | }
39 |
40 | // package scope setters for unit testing
41 |
42 | static void setJenkinsInstanceProvider(JenkinsInstanceProvider jenkinsInstanceProvider) {
43 | AbstractPromotionStatusProvider.jenkinsInstanceProvider = jenkinsInstanceProvider;
44 | }
45 |
46 | // Decorators to make code unit-testable
47 |
48 | static class JenkinsInstanceProvider {
49 | public Jenkins getJenkinsInstance() {
50 | return Jenkins.getInstance();
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/resolver/CoreCauseResolverTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.resolver;
19 |
20 | import hudson.cli.BuildCommand;
21 | import hudson.model.Cause;
22 | import org.junit.Rule;
23 | import org.junit.Test;
24 | import org.jvnet.hudson.test.JenkinsRule;
25 | import org.jvnet.hudson.test.WithoutJenkins;
26 | import se.diabol.jenkins.pipeline.domain.TriggerCause;
27 |
28 | import static org.junit.Assert.assertEquals;
29 | import static org.junit.Assert.assertNotNull;
30 |
31 | public class CoreCauseResolverTest {
32 |
33 | @Rule
34 | public JenkinsRule jenkins = new JenkinsRule();
35 |
36 | private CoreCauseResolver resolver = new CoreCauseResolver();
37 |
38 | @Test
39 | @WithoutJenkins
40 | public void shouldResolveRemoteCause() {
41 | TriggerCause triggerCause = resolver.resolveCause(new Cause.RemoteCause("hostname", "note"));
42 | assertNotNull(triggerCause);
43 | assertEquals(TriggerCause.TYPE_REMOTE, triggerCause.getType());
44 | }
45 |
46 | @Test
47 | public void shouldResolveCliCause() {
48 | TriggerCause triggerCause = resolver.resolveCause(new BuildCommand.CLICause("username"));
49 | assertNotNull(triggerCause);
50 | assertEquals(TriggerCause.TYPE_MANUAL, triggerCause.getType());
51 | }
52 |
53 | @Test
54 | public void shouldYieldAnonymousForUnknownUser() {
55 | assertEquals("anonymous", CoreCauseResolver.getDisplayName(null));
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/test/resources/se/diabol/jenkins/pipeline/functionaltest/GuiFunctionalIT/DashboardViewPage.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Dashboard
5 | false
6 | false
7 |
8 |
9 |
10 | A
11 | B
12 | C
13 | D
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | false
26 | false
27 | false
28 | 50%
29 | 50%
30 |
31 |
32 |
33 |
34 | dashboard_portlet_30762
35 | ComponentA
36 | A
37 |
38 | 15834
39 |
40 |
41 | dashboard_portlet_31401
42 | ComponentC
43 | C
44 |
45 | 12099
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/resolver/SubProjectRelationshipResolverTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.resolver;
19 |
20 | import hudson.model.AbstractProject;
21 | import hudson.model.FreeStyleProject;
22 | import hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig;
23 | import hudson.plugins.parameterizedtrigger.BlockingBehaviour;
24 | import hudson.plugins.parameterizedtrigger.TriggerBuilder;
25 | import org.junit.Rule;
26 | import org.junit.Test;
27 | import org.jvnet.hudson.test.JenkinsRule;
28 |
29 | import java.util.List;
30 |
31 | import static org.junit.Assert.assertEquals;
32 |
33 | public class SubProjectRelationshipResolverTest {
34 | @Rule
35 | public JenkinsRule jenkins = new JenkinsRule();
36 |
37 | @Test
38 | public void testExtractPipelineWithSubProjects() throws Exception {
39 | FreeStyleProject build = jenkins.createFreeStyleProject("build");
40 | FreeStyleProject sonar = jenkins.createFreeStyleProject("sonar");
41 |
42 | build.getBuildersList().add(new TriggerBuilder(new BlockableBuildTriggerConfig("sonar", new BlockingBehaviour("never", "never", "never"), null)));
43 |
44 | jenkins.getInstance().rebuildDependencyGraph();
45 | SubProjectRelationshipResolver resolver = new SubProjectRelationshipResolver();
46 | List downStreams = resolver.getDownstreamProjects(build);
47 | assertEquals(1, downStreams.size());
48 | assertEquals(sonar, downStreams.get(0));
49 |
50 |
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/domain/status/promotion/AbstractPromotionStatusProviderTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain.status.promotion;
19 |
20 | import static org.junit.Assert.assertNotNull;
21 | import static org.junit.Assert.assertSame;
22 | import static org.mockito.Mockito.mock;
23 | import static org.mockito.Mockito.when;
24 |
25 | import hudson.ExtensionList;
26 | import jenkins.model.Jenkins;
27 |
28 | import org.junit.Test;
29 |
30 | public class AbstractPromotionStatusProviderTest {
31 |
32 | @Test
33 | public void testGetAll() {
34 | final Jenkins mockJenkins = mock(Jenkins.class);
35 |
36 | @SuppressWarnings("unchecked")
37 | final ExtensionList mockExtensionList = mock(ExtensionList.class);
38 | when(mockJenkins.getExtensionList(AbstractPromotionStatusProvider.class)).thenReturn(mockExtensionList);
39 |
40 | final AbstractPromotionStatusProvider.JenkinsInstanceProvider mockJenkinsInstanceProvider =
41 | mock(AbstractPromotionStatusProvider.JenkinsInstanceProvider.class);
42 | when(mockJenkinsInstanceProvider.getJenkinsInstance()).thenReturn(mockJenkins);
43 |
44 | AbstractPromotionStatusProvider.setJenkinsInstanceProvider(mockJenkinsInstanceProvider);
45 |
46 | final ExtensionList extensionList = AbstractPromotionStatusProvider.all();
47 | assertNotNull(extensionList);
48 | assertSame(mockExtensionList, extensionList);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/domain/UserInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain;
19 |
20 | import hudson.model.User;
21 | import org.kohsuke.stapler.export.Exported;
22 | import se.diabol.jenkins.core.AbstractItem;
23 |
24 | import java.util.HashSet;
25 | import java.util.List;
26 | import java.util.Set;
27 |
28 | public class UserInfo extends AbstractItem {
29 |
30 | private final String url;
31 |
32 | public UserInfo(String name, String url) {
33 | super(name);
34 | this.url = url;
35 | }
36 |
37 | @Exported
38 | public String getUrl() {
39 | return url;
40 | }
41 |
42 | public static UserInfo getUser(User user) {
43 | return new UserInfo(user.getDisplayName(), user.getUrl());
44 | }
45 |
46 | public static Set getContributors(List changes) {
47 | Set contributors = new HashSet<>();
48 | for (Change change : changes) {
49 | contributors.add(change.getAuthor());
50 | }
51 | return contributors;
52 | }
53 |
54 | @Override
55 | public boolean equals(Object obj) {
56 | if (this == obj) {
57 | return true;
58 | }
59 | if (obj == null || getClass() != obj.getClass()) {
60 | return false;
61 | }
62 |
63 | UserInfo userInfo = (UserInfo) obj;
64 |
65 | return userInfo.getName().equals(getName());
66 | }
67 |
68 | @Override
69 | public int hashCode() {
70 | return getName().hashCode();
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/domain/status/promotion/PromotionStatus.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain.status.promotion;
19 |
20 | import org.kohsuke.stapler.export.Exported;
21 | import org.kohsuke.stapler.export.ExportedBean;
22 | import se.diabol.jenkins.core.AbstractItem;
23 |
24 | import java.util.List;
25 |
26 | @ExportedBean(defaultVisibility = AbstractItem.VISIBILITY)
27 | public class PromotionStatus {
28 | private final String name;
29 | private final long duration;
30 | private final long startTime;
31 | private final String user;
32 | private final String icon;
33 | private final List params;
34 |
35 | public PromotionStatus(String name, long startTime, long duration, String user, String icon, List params) {
36 | this.name = name;
37 | this.startTime = startTime;
38 | this.duration = duration;
39 | this.user = user;
40 | this.icon = icon;
41 | this.params = params;
42 | }
43 |
44 | @Exported
45 | public String getName() {
46 | return name;
47 | }
48 |
49 | @Exported
50 | public long getStartTime() {
51 | return startTime;
52 | }
53 |
54 | @Exported
55 | public long getDuration() {
56 | return duration;
57 | }
58 |
59 | @Exported
60 | public String getUser() {
61 | return user;
62 | }
63 |
64 | @Exported
65 | public String getIcon() {
66 | return icon;
67 | }
68 |
69 | @Exported
70 | public List getParams() {
71 | return params;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/CauseResolver.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline;
19 |
20 | import hudson.ExtensionPoint;
21 | import hudson.model.Cause;
22 | import se.diabol.jenkins.pipeline.domain.TriggerCause;
23 | import se.diabol.jenkins.pipeline.util.JenkinsUtil;
24 |
25 | import java.util.List;
26 | import javax.annotation.CheckForNull;
27 |
28 | public abstract class CauseResolver implements ExtensionPoint {
29 |
30 | /**
31 | * Resolves the Cause and returns a TriggerCause or null if not found.
32 | *
33 | * @param cause cause from the Jenkins build
34 | * @return a TriggerCause or null if the CauseResolver implementation cant find a proper cause indication that
35 | * other resolvers should make a try
36 | */
37 | @CheckForNull
38 | public abstract TriggerCause resolveCause(Cause cause);
39 |
40 | /**
41 | * Returns all loaded implementations of this extension point.
42 | *
43 | * @return all loaded implementations of this extension point.
44 | */
45 | public static List all() {
46 | return JenkinsUtil.getInstance().getExtensionList(CauseResolver.class);
47 | }
48 |
49 | public static TriggerCause getTrigger(Cause cause) {
50 | List resolvers = all();
51 | for (CauseResolver resolver : resolvers) {
52 | TriggerCause triggerCause = resolver.resolveCause(cause);
53 | if (triggerCause != null) {
54 | return triggerCause;
55 | }
56 | }
57 | return new TriggerCause(TriggerCause.TYPE_UNKNOWN, "unknown cause");
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/trigger/ManualTriggerFactoryTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.trigger;
19 |
20 | import static org.junit.Assert.assertNotNull;
21 | import static org.junit.Assert.assertNull;
22 |
23 | import au.com.centrumsystems.hudson.plugin.buildpipeline.trigger.BuildPipelineTrigger;
24 | import hudson.model.FreeStyleProject;
25 | import org.junit.Rule;
26 | import org.junit.Test;
27 | import org.jvnet.hudson.test.JenkinsRule;
28 | import org.jvnet.hudson.test.WithoutJenkins;
29 | import se.diabol.jenkins.pipeline.test.TestUtil;
30 |
31 | public class ManualTriggerFactoryTest {
32 |
33 | @Rule
34 | public JenkinsRule jenkins = new JenkinsRule();
35 |
36 | @Test
37 | @WithoutJenkins
38 | public void testValidUtilClass() throws Exception {
39 | TestUtil.assertUtilityClassWellDefined(ManualTriggerFactory.class);
40 | }
41 |
42 | @Test
43 | public void testNotFound() throws Exception {
44 | FreeStyleProject projectA = jenkins.createFreeStyleProject("a");
45 | FreeStyleProject projectB = jenkins.createFreeStyleProject("b");
46 | assertNull(ManualTriggerFactory.getManualTrigger(projectB, projectA));
47 | }
48 |
49 | @Test
50 | public void testFound() throws Exception {
51 | FreeStyleProject projectA = jenkins.createFreeStyleProject("a");
52 | FreeStyleProject projectB = jenkins.createFreeStyleProject("b");
53 | projectA.getPublishersList().add(new BuildPipelineTrigger("b", null));
54 | jenkins.getInstance().rebuildDependencyGraph();
55 | assertNotNull(ManualTriggerFactory.getManualTrigger(projectB, projectA));
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/resources/se/diabol/jenkins/pipeline/DeliveryPipelineView/index.jelly:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 | ${h.initPageVariables(context)}
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
26 |
27 |
28 |
29 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/src/main/resources/se/diabol/jenkins/workflow/WorkflowPipelineView/index.jelly:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 | ${h.initPageVariables(context)}
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
26 |
27 |
28 |
29 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/test/TestUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.test;
19 |
20 | import org.junit.Assert;
21 |
22 | import java.lang.reflect.Constructor;
23 | import java.lang.reflect.InvocationTargetException;
24 | import java.lang.reflect.Method;
25 | import java.lang.reflect.Modifier;
26 |
27 | public final class TestUtil {
28 |
29 | private TestUtil() {
30 | }
31 |
32 | /**
33 | * Verifies that a utility class is well defined.
34 | * Stolen from http://stackoverflow.com/a/10872497
35 | *
36 | * @param clazz
37 | * utility class to verify.
38 | */
39 | public static void assertUtilityClassWellDefined(final Class> clazz)
40 | throws NoSuchMethodException, InvocationTargetException,
41 | InstantiationException, IllegalAccessException {
42 | Assert.assertTrue("class must be final",
43 | Modifier.isFinal(clazz.getModifiers()));
44 | Assert.assertEquals("There must be only one constructor", 1,
45 | clazz.getDeclaredConstructors().length);
46 | final Constructor> constructor = clazz.getDeclaredConstructor();
47 | if (constructor.isAccessible()
48 | || !Modifier.isPrivate(constructor.getModifiers())) {
49 | Assert.fail("constructor is not private");
50 | }
51 | constructor.setAccessible(true);
52 | constructor.newInstance();
53 | constructor.setAccessible(false);
54 | for (final Method method : clazz.getMethods()) {
55 | if (!Modifier.isStatic(method.getModifiers())
56 | && method.getDeclaringClass().equals(clazz)) {
57 | Assert.fail("there exists a non-static method:" + method);
58 | }
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/domain/results/TestResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain.results;
19 |
20 | import hudson.model.AbstractBuild;
21 | import hudson.tasks.test.AbstractTestResultAction;
22 | import org.kohsuke.stapler.export.Exported;
23 |
24 | import java.util.ArrayList;
25 | import java.util.Collections;
26 | import java.util.List;
27 |
28 | public class TestResult extends Result {
29 |
30 | private int failed;
31 | private int skipped;
32 | private int total;
33 |
34 | public TestResult(String name, String url, int failed, int skipped, int total) {
35 | super(name, url);
36 | this.failed = failed;
37 | this.skipped = skipped;
38 | this.total = total;
39 | }
40 |
41 |
42 | @Exported
43 | public int getFailed() {
44 | return failed;
45 | }
46 |
47 | @Exported
48 | public int getSkipped() {
49 | return skipped;
50 | }
51 |
52 | @Exported
53 | public int getTotal() {
54 | return total;
55 | }
56 |
57 | public static List getResults(AbstractBuild, ?> build) {
58 | if (build != null) {
59 | List result = new ArrayList<>();
60 | AbstractTestResultAction resultAction = build.getAction(AbstractTestResultAction.class);
61 | if (resultAction != null) {
62 | result.add(new TestResult(
63 | resultAction.getDisplayName(),
64 | build.getUrl() + resultAction.getUrlName(),
65 | resultAction.getFailCount(),
66 | resultAction.getSkipCount(),
67 | resultAction.getTotalCount()));
68 | }
69 | return result;
70 | }
71 | return Collections.emptyList();
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/workflow/model/Component.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.workflow.model;
19 |
20 | import static com.google.common.base.MoreObjects.toStringHelper;
21 |
22 | import com.google.common.collect.ImmutableList;
23 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
24 | import org.kohsuke.stapler.export.Exported;
25 | import org.kohsuke.stapler.export.ExportedBean;
26 | import se.diabol.jenkins.core.AbstractItem;
27 | import se.diabol.jenkins.core.GenericComponent;
28 |
29 | import java.util.Collections;
30 | import java.util.List;
31 |
32 | @ExportedBean(defaultVisibility = AbstractItem.VISIBILITY)
33 | public class Component extends GenericComponent {
34 | private final List pipelines;
35 | private final WorkflowJob workflowJob;
36 |
37 | public Component(String name, WorkflowJob job, List pipelines) {
38 | super(name);
39 | this.workflowJob = job;
40 | if (pipelines != null) {
41 | this.pipelines = ImmutableList.copyOf(pipelines);
42 | } else {
43 | this.pipelines = Collections.emptyList();
44 | }
45 | }
46 |
47 | @Exported
48 | public boolean isWorkflowComponent() {
49 | return true;
50 | }
51 |
52 | @Exported
53 | public String getWorkflowUrl() {
54 | return workflowJob.getUrl();
55 | }
56 |
57 | @Exported
58 | public WorkflowJob getWorkflowJob() {
59 | return workflowJob;
60 | }
61 |
62 | @Exported
63 | public String getFullJobName() {
64 | return workflowJob.getFullName();
65 | }
66 |
67 | @Exported
68 | public List getPipelines() {
69 | return pipelines;
70 | }
71 |
72 | @Override
73 | public String toString() {
74 | return toStringHelper(this).add("name", getName()).add("pipelines", pipelines).toString();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/domain/status/StatusFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain.status;
19 |
20 | import se.diabol.jenkins.pipeline.domain.status.promotion.PromotionStatus;
21 |
22 | import java.util.List;
23 |
24 | public final class StatusFactory {
25 |
26 | private StatusFactory() {
27 | }
28 |
29 | public static Status idle() {
30 | return new SimpleStatus(StatusType.IDLE, -1, -1);
31 | }
32 |
33 | public static Status running(int percentage, long lastActivity, long duration) {
34 | return new Running(percentage, lastActivity, duration);
35 | }
36 |
37 | public static Status queued(long lastActivity) {
38 | return new SimpleStatus(StatusType.QUEUED, lastActivity, -1);
39 | }
40 |
41 | public static Status success(long lastActivity, long duration, boolean promoted, List promotions) {
42 | return new SimpleStatus(StatusType.SUCCESS, lastActivity, duration, promoted, promotions);
43 | }
44 |
45 | public static Status failed(long lastActivity, long duration, boolean promoted, List promotions) {
46 | return new SimpleStatus(StatusType.FAILED, lastActivity, duration, promoted, promotions);
47 | }
48 |
49 | public static Status unstable(long lastActivity, long duration) {
50 | return new SimpleStatus(StatusType.UNSTABLE, lastActivity, duration);
51 | }
52 |
53 | public static Status cancelled(long lastActivity, long duration) {
54 | return new SimpleStatus(StatusType.CANCELLED, lastActivity, duration);
55 | }
56 |
57 | public static Status notBuilt(long lastActivity, long duration) {
58 | return new SimpleStatus(StatusType.NOT_BUILT, lastActivity, duration);
59 | }
60 |
61 | public static Status disabled() {
62 | return new SimpleStatus(StatusType.DISABLED, -1, -1);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/portlet/ReadOnlyDeliveryPipelineViewTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.portlet;
19 |
20 | import org.junit.Test;
21 | import org.junit.runner.RunWith;
22 | import org.mockito.junit.MockitoJUnitRunner;
23 |
24 | import static org.junit.Assert.assertFalse;
25 | import static org.junit.Assert.assertNull;
26 | import static org.junit.Assert.assertEquals;
27 | import static org.junit.Assert.assertNotNull;
28 |
29 | @RunWith(MockitoJUnitRunner.class)
30 | public class ReadOnlyDeliveryPipelineViewTest {
31 |
32 | @Test
33 | public void shouldHaveDefaults() {
34 | ReadOnlyDeliveryPipelineView view = new ReadOnlyDeliveryPipelineView("name");
35 | assertEquals(3, view.getNoOfPipelines());
36 | assertEquals(1, view.getNoOfColumns());
37 | assertEquals(2, view.getUpdateInterval());
38 | assertEquals("none", view.getSorting());
39 | assertNull(view.getEmbeddedCss());
40 | assertNull(view.getFullScreenCss());
41 | assertNull(view.getComponentSpecs());
42 | assertFalse(view.isShowAggregatedPipeline());
43 | assertFalse(view.getShowAvatars());
44 | assertFalse(view.isShowChanges());
45 | assertFalse(view.isAllowManualTriggers());
46 | assertFalse(view.isShowTotalBuildTime());
47 | assertFalse(view.isAllowRebuild());
48 | assertFalse(view.isShowDescription());
49 | assertFalse(view.isShowPromotions());
50 | assertFalse(view.isShowTestResults());
51 | assertFalse(view.isShowStaticAnalysisResults());
52 | assertFalse(view.getPagingEnabled());
53 | assertFalse(view.isAllowPipelineStart());
54 | assertNotNull(view.getId());
55 | assertFalse(view.getIsPortletView());
56 | assertFalse(view.isShowAggregatedChanges());
57 | assertNull(view.getAggregatedChangesGroupingPattern());
58 | assertFalse(view.isEditable());
59 | assertFalse(view.hasPermission(null));
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/functionaltest/DeliveryPipelinePage.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.functionaltest;
19 |
20 | import org.openqa.selenium.By;
21 | import org.openqa.selenium.JavascriptExecutor;
22 | import org.openqa.selenium.Keys;
23 | import org.openqa.selenium.WebDriver;
24 | import org.openqa.selenium.WebElement;
25 | import org.openqa.selenium.support.ui.ExpectedCondition;
26 | import org.openqa.selenium.support.ui.WebDriverWait;
27 |
28 | public class DeliveryPipelinePage {
29 |
30 | private WebDriver webDriver;
31 | private String baseUrl;
32 | private String viewUri;
33 |
34 |
35 | public DeliveryPipelinePage(WebDriver webDriver, String baseUrl, String viewUri) {
36 | this.webDriver = webDriver;
37 | this.baseUrl = baseUrl;
38 | this.viewUri = viewUri;
39 | }
40 |
41 |
42 | public void open() {
43 | webDriver.get(baseUrl + viewUri);
44 | }
45 |
46 |
47 | public void triggerManual(String build) {
48 |
49 | SeleniumUtil.waitForElement(webDriver,"manual-task-" + build).click();
50 |
51 | }
52 |
53 | public void triggerRebuild(String build) {
54 | String id = "rebuild-task-" + build;
55 | SeleniumUtil.waitForElement(webDriver,"rebuild-task-" + build).click();
56 | }
57 |
58 | public void triggerNewPipelineBuild(String no) {
59 | SeleniumUtil.waitForElement(webDriver,"startpipeline-" + no).sendKeys(Keys.RETURN);
60 | SeleniumUtil.waitForElement(webDriver,"task-Start0.timestamp");
61 | }
62 |
63 | public void triggerNewParameterizedPipelineBuild(String no) {
64 | SeleniumUtil.waitForElement(webDriver,"startpipeline-" + no).sendKeys(Keys.RETURN);
65 | /* this build requires parameter */
66 | SeleniumUtil.waitForElement(webDriver,"yui-gen5-button").click();
67 | }
68 |
69 | public String getJsPlumbUtilityVariable() {
70 | JavascriptExecutor jse = (JavascriptExecutor) webDriver;
71 | return jse.executeScript("return jsPlumbUtilityVariable.length").toString();
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/pipeline/portlet/ReadOnlyDeliveryPipelineView.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.portlet;
19 |
20 | import hudson.model.Api;
21 | import hudson.model.ViewGroup;
22 | import hudson.security.Permission;
23 | import org.kohsuke.stapler.export.Exported;
24 | import se.diabol.jenkins.pipeline.DeliveryPipelineView;
25 | import se.diabol.jenkins.pipeline.PipelineApi;
26 |
27 | import java.util.Random;
28 |
29 | public class ReadOnlyDeliveryPipelineView extends DeliveryPipelineView {
30 |
31 | private static final int BOUND = 32000;
32 | private static Random GENERATOR = new Random();
33 | private String id = null;
34 | private String viewUrl = null;
35 | private boolean isPortletView = false;
36 |
37 | public ReadOnlyDeliveryPipelineView(String name) {
38 | super(name);
39 | this.id = Integer.toString(GENERATOR.nextInt(BOUND));
40 | }
41 |
42 | public ReadOnlyDeliveryPipelineView(String name, ViewGroup itemGroup) {
43 | super(name, itemGroup);
44 | this.id = Integer.toString(GENERATOR.nextInt(BOUND));
45 | }
46 |
47 | public String getId() {
48 | return id == null ? setIdValue() : id;
49 | }
50 |
51 | String setIdValue() {
52 | this.id = Integer.toString(GENERATOR.nextInt(BOUND));
53 | return this.id;
54 | }
55 |
56 | public void setId(String id) {
57 | this.id = id;
58 | }
59 |
60 | public boolean getIsPortletView() {
61 | return isPortletView;
62 | }
63 |
64 | public void setIsPortletView(boolean isPortletView) {
65 | this.isPortletView = isPortletView;
66 | }
67 |
68 | @Override
69 | @Exported
70 | public String getViewUrl() {
71 | return (this.viewUrl == null ? super.getViewUrl() : viewUrl);
72 | }
73 |
74 | public void setViewUrl(String viewUrl) {
75 | this.viewUrl = viewUrl;
76 | }
77 |
78 | @Override
79 | public boolean hasPermission(final Permission permission) {
80 | return false;
81 | }
82 |
83 | @Override
84 | public boolean isEditable() {
85 | return false;
86 | }
87 |
88 | @Override
89 | public Api getApi() {
90 | return new PipelineApi(this);
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/domain/results/TestResultTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain.results;
19 |
20 | import hudson.model.AbstractBuild;
21 | import hudson.model.FreeStyleBuild;
22 | import hudson.tasks.junit.TestResultAction;
23 | import hudson.tasks.test.AbstractTestResultAction;
24 | import hudson.tasks.test.AggregatedTestResultAction;
25 | import org.junit.Test;
26 |
27 | import java.util.List;
28 |
29 | import static org.junit.Assert.assertEquals;
30 | import static org.junit.Assert.assertNotNull;
31 | import static org.mockito.Mockito.mock;
32 | import static org.mockito.Mockito.when;
33 |
34 | public class TestResultTest {
35 |
36 | @Test
37 | public void testGetTestResult() {
38 | AbstractBuild, ?> build = mock(AbstractBuild.class);
39 | AggregatedTestResultAction tests = mock(AggregatedTestResultAction.class);
40 | when(build.getAction(AbstractTestResultAction.class)).thenReturn(tests);
41 | when(tests.getDisplayName()).thenReturn("Test Result");
42 | when(tests.getFailCount()).thenReturn(1);
43 | when(tests.getSkipCount()).thenReturn(0);
44 | when(tests.getTotalCount()).thenReturn(11);
45 |
46 | List result = TestResult.getResults(build);
47 | assertNotNull(result);
48 | assertEquals(1, result.get(0).getFailed());
49 | assertEquals(0, result.get(0).getSkipped());
50 | assertEquals(11, result.get(0).getTotal());
51 | assertNotNull(result.get(0).getUrl());
52 | assertNotNull(result.get(0).getName());
53 | }
54 |
55 | @Test
56 | public void testGetTestResultFreeStyleBuild() {
57 | FreeStyleBuild build = mock(FreeStyleBuild.class);
58 | TestResultAction action = mock(TestResultAction.class);
59 | when(build.getAction(AbstractTestResultAction.class)).thenReturn(action);
60 |
61 | List result = TestResult.getResults(build);
62 | assertNotNull(result);
63 | assertEquals(1, result.size());
64 | }
65 |
66 | @Test
67 | public void testGetTestResultBuildNull() {
68 | List result = TestResult.getResults(null);
69 | assertNotNull(result);
70 | assertEquals(0, result.size());
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/workflow/util/Util.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.workflow.util;
19 |
20 | import org.jenkinsci.plugins.workflow.graph.FlowNode;
21 | import se.diabol.jenkins.workflow.api.Run;
22 | import se.diabol.jenkins.workflow.step.TaskAction;
23 | import se.diabol.jenkins.workflow.step.TaskFinishedAction;
24 |
25 | import java.util.ArrayList;
26 | import java.util.List;
27 | import java.util.Optional;
28 |
29 | public final class Util {
30 |
31 | private Util() {
32 | }
33 |
34 | public static List getTaskNodes(List stageNodes) {
35 | List result = new ArrayList<>();
36 | for (FlowNode stageNode : stageNodes) {
37 | if (isTaskNode(stageNode)) {
38 | result.add(stageNode);
39 | }
40 | }
41 | return result;
42 | }
43 |
44 | public static Optional getParentNodeWithTaskFinishedAction(FlowNode taskNode) {
45 | return taskNode.getParents().stream()
46 | .filter(parent -> parent.getAction(TaskFinishedAction.class) != null)
47 | .findFirst();
48 | }
49 |
50 | public static boolean isAnyParentNodeContainingTaskFinishedAction(FlowNode taskNode) {
51 | if (taskNode != null && !taskNode.getParents().isEmpty()) {
52 | Optional parentWithTaskFinishedAction = getParentNodeWithTaskFinishedAction(taskNode);
53 | return parentWithTaskFinishedAction.isPresent();
54 | }
55 | return false;
56 | }
57 |
58 | public static Run getRunById(List runs, int buildNumber) {
59 | if (runs == null || runs.isEmpty()) {
60 | return null;
61 | }
62 | String id = "" + buildNumber;
63 | for (Run run : runs) {
64 | if (id.equals(run.id)) {
65 | return run;
66 | }
67 | }
68 | return null;
69 | }
70 |
71 | public static T head(List list) {
72 | if (list != null && !list.isEmpty()) {
73 | return list.get(0);
74 | } else {
75 | return null;
76 | }
77 | }
78 |
79 | private static boolean isTaskNode(FlowNode flowNode) {
80 | return flowNode.getAction(TaskAction.class) != null;
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/sort/LatestActivityComparatorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.sort;
19 |
20 | import static org.junit.Assert.assertEquals;
21 | import static se.diabol.jenkins.pipeline.domain.status.StatusType.SUCCESS;
22 | import static se.diabol.jenkins.pipeline.test.PipelineUtil.createComponent;
23 | import static se.diabol.jenkins.pipeline.test.PipelineUtil.status;
24 |
25 | import org.joda.time.DateTime;
26 | import org.junit.Test;
27 | import se.diabol.jenkins.pipeline.domain.Component;
28 | import se.diabol.jenkins.pipeline.domain.status.StatusType;
29 | import se.diabol.jenkins.workflow.model.WorkflowStatus;
30 |
31 | import java.util.ArrayList;
32 | import java.util.Arrays;
33 | import java.util.Collections;
34 | import java.util.List;
35 |
36 | public class LatestActivityComparatorTest {
37 |
38 | @Test
39 | public void shouldSortRecentlyRunDeliveryPipelineFirst() {
40 | Component componentRunLongAgo = createComponent(status(SUCCESS, new DateTime().minusDays(2)));
41 | Component componentRunRecently = createComponent(status(SUCCESS, new DateTime().minusDays(1)));
42 | List list = new ArrayList<>();
43 | list.add(componentRunRecently);
44 | list.add(componentRunLongAgo);
45 | list.sort(new LatestActivityComparator.DescriptorImpl().createInstance());
46 | assertEquals(componentRunRecently, list.get(0));
47 | assertEquals(componentRunLongAgo, list.get(1));
48 | }
49 |
50 | @Test
51 | public void shouldSortRecentlyRunWorkflowPipelineFirst() {
52 | se.diabol.jenkins.workflow.model.Component componentRunLongAgo = createComponent(
53 | new WorkflowStatus(StatusType.SUCCESS, 1000, 100));
54 | se.diabol.jenkins.workflow.model.Component componentRunRecently = createComponent(
55 | new WorkflowStatus(StatusType.SUCCESS, 9000, 100));
56 | List components = Arrays
57 | .asList(componentRunLongAgo, componentRunRecently);
58 | components.sort(new LatestActivityComparator.DescriptorImpl().createInstance());
59 | assertEquals(componentRunRecently, components.get(0));
60 | assertEquals(componentRunLongAgo, components.get(1));
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/test/java/se/diabol/jenkins/pipeline/domain/RouteTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.pipeline.domain;
19 |
20 | import org.junit.Test;
21 | import se.diabol.jenkins.pipeline.domain.status.Status;
22 | import se.diabol.jenkins.pipeline.domain.task.Task;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | import static org.junit.Assert.assertEquals;
28 | import static org.mockito.Mockito.mock;
29 | import static org.mockito.Mockito.when;
30 |
31 | public class RouteTest {
32 |
33 | @Test
34 | public void testSetTasks() {
35 | Route route = new Route();
36 | assertEquals(0, route.getTasks().size());
37 |
38 | List tasks = new ArrayList<>();
39 | tasks.add(mock(Task.class));
40 | tasks.add(mock(Task.class));
41 | tasks.add(mock(Task.class));
42 |
43 | route.setTasks(tasks);
44 | assertEquals(3, route.getTasks().size());
45 | }
46 |
47 | @Test
48 | public void testGetTotalBuildTime() {
49 | Route route = new Route();
50 | assertEquals(0, route.getTotalBuildTime());
51 |
52 | List tasks = new ArrayList<>();
53 | Task task1 = mock(Task.class);
54 | Status status1 = mock(Status.class);
55 | when(status1.getDuration()).thenReturn(100L);
56 | when(task1.getStatus()).thenReturn(status1);
57 |
58 | Task task2 = mock(Task.class);
59 | Status status2 = mock(Status.class);
60 | when(status2.getDuration()).thenReturn(200L);
61 | when(task2.getStatus()).thenReturn(status2);
62 |
63 | Task task3 = mock(Task.class);
64 | Status status3 = mock(Status.class);
65 | when(status3.getDuration()).thenReturn(300L);
66 | when(task3.getStatus()).thenReturn(status3);
67 |
68 | tasks.add(task1);
69 | tasks.add(task2);
70 | tasks.add(task3);
71 | route.setTasks(tasks);
72 |
73 | assertEquals(600L, route.getTotalBuildTime());
74 | }
75 |
76 | @Test
77 | public void testAddTask() {
78 | Route route = new Route();
79 | assertEquals(0, route.getTasks().size());
80 |
81 | route.addTask(mock(Task.class));
82 | assertEquals(1, route.getTasks().size());
83 |
84 | route.addTask(mock(Task.class));
85 | route.addTask(mock(Task.class));
86 | assertEquals(3, route.getTasks().size());
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/se/diabol/jenkins/core/PipelineView.java:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of Delivery Pipeline Plugin.
3 |
4 | Delivery Pipeline Plugin is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | Delivery Pipeline Plugin is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with Delivery Pipeline Plugin.
16 | If not, see .
17 | */
18 | package se.diabol.jenkins.core;
19 |
20 | import org.acegisecurity.AuthenticationException;
21 | import se.diabol.jenkins.pipeline.trigger.TriggerException;
22 |
23 | import java.util.List;
24 |
25 | /**
26 | * Interface defining common methods for delivery pipeline views.
27 | * Note that Jenkins does NOT support the following:
28 | *
29 | *
Java 8 interface default methods
30 | *
@Exported annotations on interface methods - these needs to be set on the method in the
31 | * implementing class
32 | *
33 | */
34 | public interface PipelineView {
35 |
36 | void triggerManual(String projectName, String upstreamName, String buildId)
37 | throws TriggerException, AuthenticationException;
38 |
39 | void triggerRebuild(String projectName, String buildId);
40 |
41 | void abortBuild(String projectName, String buildId) throws TriggerException, AuthenticationException;
42 |
43 | /**
44 | * Whether to allow a new pipeline to be started from the pipeline view.
45 | * Expected to be annotated with @Exported for consumption from the view page.
46 | *
47 | * @return whether to allow a new pipeline to be started from the pipeline view.
48 | */
49 | boolean isAllowPipelineStart();
50 |
51 | /**
52 | * Whether to allow running pipelines to be aborted from the pipeline view.
53 | * Expected to be annotated with @Exported for consumption from the view page.
54 | *
55 | * @return whether to allow pipelines to be aborted from the pipeline view.
56 | */
57 | boolean isAllowAbort();
58 |
59 | /**
60 | * A date time string representing when the pipeline view was last updated.
61 | * Expected to be annotated with @Exported for consumption from the view page.
62 | *
63 | * @return a string representation on when the pipeline view was last updated.
64 | */
65 | String getLastUpdated();
66 |
67 | /**
68 | * Exposes any error that is currently associated with the pipeline view.
69 | *
70 | * @return the error currently associated with this pipeline view.
71 | */
72 | String getError();
73 |
74 | /**
75 | * Resolve the pipelines associated with this view.
76 | * Expected to be annotated with @Exported for consumption from the view page.
77 | *
78 | * @return a list of components associated with this pipeline view.
79 | */
80 | List extends GenericComponent> getPipelines();
81 | }
82 |
--------------------------------------------------------------------------------