Skip to content

Commit

Permalink
[JENKINS-21337] Add support for cloudbees-folders
Browse files Browse the repository at this point in the history
Added CloudbeedFoldersBasedInclusionStrategy to enable
JobGroup creation based on a Folder.
  • Loading branch information
emsa23 committed Jan 13, 2014
1 parent 7178c46 commit 6744810
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pom.xml
Expand Up @@ -58,6 +58,15 @@
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cloudbees-folder</artifactId>
<version>4.2</version>
<optional>true</optional>
</dependency>
</dependencies>

<repositories>
<repository>
Expand Down
@@ -0,0 +1,80 @@
/*
* The MIT License
*
* Copyright (c) 2014, Magnus Sandberg
*
* 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.
*/
package jenkins.advancedqueue.jobinclusion.strategy;

import hudson.Extension;
import hudson.model.Job;
import hudson.util.ListBoxModel;

import java.util.List;

import jenkins.advancedqueue.DecisionLogger;
import jenkins.advancedqueue.jobinclusion.JobInclusionStrategy;
import jenkins.model.Jenkins;

import org.kohsuke.stapler.DataBoundConstructor;

import com.cloudbees.hudson.plugins.folder.Folder;

/**
* @author Magnus Sandberg
* @since 2.7
*/
public class CloudbeesFoldersBasedJobInclusionStrategy extends JobInclusionStrategy {

@Extension(optional = true)
static public class CloudbeesFoldersBasedJobInclusionStrategyDescriptor extends
AbstractJobInclusionStrategyDescriptor<CloudbeesFoldersBasedJobInclusionStrategy> {

public CloudbeesFoldersBasedJobInclusionStrategyDescriptor() {
super("Jobs that are included in a Cloudbees Folder");
}

public ListBoxModel getListFolderItems() {
ListBoxModel items = new ListBoxModel();
List<Folder> folders = Jenkins.getInstance().getAllItems(Folder.class);
for (Folder folder : folders) {
items.add(folder.getFullName(), folder.getFullName());
}
return items;
}

};

private String folderName;

@DataBoundConstructor
public CloudbeesFoldersBasedJobInclusionStrategy(String folderName) {
this.folderName = folderName;
}

public String getFolderName() {
return folderName;
}

@Override
public boolean contains(DecisionLogger decisionLogger, Job<?, ?> job) {
return job.getFullName().startsWith(folderName);
}
}
@@ -0,0 +1,9 @@
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:l="/lib/layout" xmlns:st="jelly:stapler">
<f:entry title="Apply to Jobs in Folder">
<select name="folderName">
<j:forEach var="folder" items="${descriptor.listFolderItems}">
<f:option value="${folder.value}" selected="${folder.value==instance.folderName}">${folder.name}</f:option>
</j:forEach>
</select>
</f:entry>
</j:jelly>

0 comments on commit 6744810

Please sign in to comment.