Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dsaponenko committed Oct 6, 2016
1 parent f190bd7 commit c986dfa
Show file tree
Hide file tree
Showing 14 changed files with 711 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
@@ -0,0 +1,17 @@
# editorconfig.org

root = true

[*]
end_of_line = crlf
indent_size = 4
continuation_indent_size = 4
indent_style = space
insert_final_newline = false
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[**.{js,css,less,html,htm}]
charset = utf-8
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
target
work
workflow-multibranch.iml
.idea
211 changes: 211 additions & 0 deletions pom.xml
@@ -0,0 +1,211 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright 2015, CloudBees, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.12</version>
<relativePath/>
</parent>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-multibranch-def</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Pipeline: Multibranch with defaults</name>
<url>https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Multibranch+Def+Plugin</url>
<description>Enhances Pipeline plugin to handle branches better by automatically grouping builds from different
branches. Supports enable one default pipeline
</description>
<licenses>
<license>
<name>MIT License</name>
<url>http://opensource.org/licenses/MIT</url>
</license>
</licenses>
<scm>
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>HEAD</tag>
</scm>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<properties>
<jenkins.version>1.642.3</jenkins.version>
</properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-multibranch</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>config-file-provider</artifactId>
<version>2.11</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-cps-global-lib</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.3</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-support</artifactId>
<version>2.2</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.10</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-scm-step</artifactId>
<version>2.2</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>2.5.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>subversion</artifactId>
<version>2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>2.5.2</version>
<classifier>tests</classifier>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>subversion</artifactId>
<version>2.6</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-job</artifactId>
<version>2.6</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.modules</groupId>
<artifactId>sshd</artifactId>
<version>1.6</version>
<scope>test
</scope><!-- from git-server via workflow-cps-global-lib and otherwise unavailable during tests -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-auth</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<configuration>
<loggers>
<org.jenkinsci.plugins.workflow.multibranch>FINE</org.jenkinsci.plugins.workflow.multibranch>
</loggers>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,64 @@
package org.jenkinsci.plugins.workflow.multibranch;

import org.jvnet.localizer.Localizable;
import org.jvnet.localizer.ResourceBundleHolder;

/**
* Generated localization support class.
*/
@SuppressWarnings({
"",
"PMD",
"all"
})
public class DefMessages {
/**
* The resource bundle reference
*/
private final static ResourceBundleHolder holder = ResourceBundleHolder.get(DefMessages.class);

/**
* Key {@code WorkflowMultiBranchDefProject.Description}: {@code Creates a
* set of Pipeline projects according to detected branches in one SCM
* repository.}.
*
* @return {@code Creates a set of Pipeline projects according to detected
* branches in one SCM repository.}
*/
public static String WorkflowMultiBranchDefProject_Description() {
return holder.format("WorkflowMultiBranchDefProject.Description");
}

/**
* Key {@code WorkflowMultiBranchDefProject.Description}: {@code Creates a
* set of Pipeline projects according to detected branches in one SCM
* repository.}.
*
* @return {@code Creates a set of Pipeline projects according to detected
* branches in one SCM repository.}
*/
public static Localizable _WorkflowMultiBranchDefProject_Description() {
return new Localizable(holder, "WorkflowMultiBranchDefProject.Description");
}

/**
* Key {@code WorkflowMultiBranchDefProject.DisplayName}: {@code Multibranch
* Pipeline}.
*
* @return {@code Multibranch Pipeline}
*/
public static String WorkflowMultiBranchDefProject_DisplayName() {
return holder.format("WorkflowMultiBranchDefProject.DisplayName");
}

/**
* Key {@code WorkflowMultiBranchDefProject.DisplayName}: {@code Multibranch
* Pipeline}.
*
* @return {@code Multibranch Pipeline}
*/
public static Localizable _WorkflowMultiBranchDefProject_DisplayName() {
return new Localizable(holder, "WorkflowMultiBranchDefProject.DisplayName");
}

}
@@ -0,0 +1,90 @@
package org.jenkinsci.plugins.workflow.multibranch;

import hudson.Extension;
import hudson.FilePath;
import hudson.model.*;
import jenkins.model.Jenkins;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.plugins.configfiles.groovy.GroovyScript;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.flow.FlowDefinition;
import org.jenkinsci.plugins.workflow.flow.FlowDefinitionDescriptor;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;

import java.io.File;
import java.util.List;

/**
* Checks out the local default version of {@link WorkflowBranchProjectFactory#SCRIPT} in order if exist:
* 1. From module checkout
* 1. From task workspace directory
* 2. From global jenkins managed files
*/
class DefaultsBinder extends FlowDefinition {

@Override
public FlowExecution create(FlowExecutionOwner handle, TaskListener listener, List<? extends Action> actions) throws Exception {
Jenkins jenkins = Jenkins.getInstance();
if (jenkins == null) {
throw new IllegalStateException("inappropriate context");
}
FilePath workspacePath = jenkins.getWorkspaceFor(((WorkflowRun) handle.getExecutable()).getParent());
if (workspacePath == null || workspacePath.child(WorkflowBranchDefProjectFactory.SCRIPT).exists()) {
throw new IllegalStateException("inappropriate context");
}

Queue.Executable executable = handle.getExecutable();
File rootDir;
if (executable != null) {
WorkflowJob workflowJob = ((WorkflowJob) handle.getExecutable().getParent());
rootDir = workflowJob.getParent().getRootDir();
if (rootDir != null) {
File localConfig = new File(rootDir + File.separator + WorkflowBranchDefProjectFactory.SCRIPT);
if (localConfig.exists()) {
return new CpsFlowDefinition(FileUtils.readFileToString(localConfig, "utf-8"), false).
create(handle, listener, actions);
}
}
}

ConfigProvider configProvider = ConfigProvider.getByIdOrNull(GroovyScript.class.getName());
if (configProvider != null) {
Config config = configProvider.getConfigById(WorkflowBranchDefProjectFactory.SCRIPT);
if (config != null) {
return new CpsFlowDefinition(config.content, false).create(handle, listener, actions);
}
}
throw new IllegalArgumentException(WorkflowBranchDefProjectFactory.SCRIPT + " not found");
}

@Extension
public static class DescriptorImpl extends FlowDefinitionDescriptor {

@Override
public String getDisplayName() {
return "Pipeline script from default " + WorkflowBranchProjectFactory.SCRIPT;
}

}

/**
* Want to display this in the r/o configuration for a branch project, but not offer it on standalone jobs or in any other context.
*/
@Extension
public static class HideMeElsewhere extends DescriptorVisibilityFilter {

@Override
public boolean filter(Object context, Descriptor descriptor) {
if (descriptor instanceof DescriptorImpl) {
return context instanceof WorkflowJob && ((WorkflowJob) context).getParent() instanceof WorkflowMultiBranchDefProject;
}
return true;
}

}
}

0 comments on commit c986dfa

Please sign in to comment.