-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # Dockerfile # plugins.txt
- Loading branch information
Showing
5 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Demo jobs | ||
=== | ||
|
||
This directory contains a set of demo `Jenkinsfile`s. | ||
System Groovy scripts process this directory and create jobs for each job. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
buildPlugin(platforms: ['linux'], | ||
repo: 'https://github.com/jenkinsci/job-restrictions-plugin.git', | ||
findbugs: [archive: true, unstableTotalAll: '0']) |
78 changes: 78 additions & 0 deletions
78
init_scripts/src/main/groovy/io/jenkins/systemgroovy/plugins/PipelineHelper.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.jenkins.systemgroovy.plugins | ||
|
||
import com.cloudbees.hudson.plugins.folder.Folder | ||
import hudson.plugins.filesystem_scm.FSSCM | ||
import org.apache.commons.io.FilenameUtils | ||
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition | ||
import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition | ||
import org.jenkinsci.plugins.workflow.job.WorkflowJob | ||
import org.jenkinsci.plugins.workflow.libs.FolderLibraries | ||
import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration | ||
import org.jenkinsci.plugins.workflow.libs.SCMRetriever | ||
|
||
/** | ||
* Helper script for Pipeline job management. | ||
* @author Oleg Nenashev | ||
* @since TODO | ||
*/ | ||
class PipelineHelper { | ||
|
||
static WorkflowJob createDemo(File file, Folder folder, String name = null, boolean useScmSource = true) { | ||
String jobName = name ?: FilenameUtils.removeExtension(file.name) | ||
def descriptionFile = new File(file.path.replace(".groovy", ".txt")) | ||
def descriptionText = descriptionFile.exists() ? descriptionFile.text : null | ||
|
||
if (useScmSource) { | ||
return createScmPipelineJob(jobName, folder, file, descriptionText) | ||
} else { | ||
return createPipelineJob(jobName, folder, file.text, true, descriptionText) | ||
} | ||
} | ||
|
||
static WorkflowJob createPipelineJob(String name, Folder folder, String script, | ||
boolean sandbox = true, String description = null) { | ||
def p = folder.createProject(WorkflowJob.class, name) | ||
if (description != null) { | ||
p.description = description | ||
} | ||
p.definition = new CpsFlowDefinition( | ||
script, | ||
sandbox | ||
) | ||
return p | ||
} | ||
|
||
static WorkflowJob createScmPipelineJob(String name, Folder folder, File script, String description = null) { | ||
def p = folder.createProject(WorkflowJob.class, name) | ||
if (description != null) { | ||
p.description = description | ||
} | ||
p.definition = new CpsScmFlowDefinition( | ||
new FSSCM(script.parent, false, false, null), | ||
script.name | ||
) | ||
return p | ||
} | ||
|
||
static WorkflowJob createBuildPluginJob(Folder folder, String repo, String organization = "jenkinsci", String nameSuffix = "", String args = null, String extras = "") { | ||
return createPipelineJob("${repo}${nameSuffix}", folder, | ||
"buildPlugin(platforms: ['linux'], repo: 'https://github.com/${organization}/${repo}.git' ${extras})", | ||
true, "Builds the ${repo} plugin" | ||
) | ||
} | ||
|
||
static def addLocalLibrary(Folder folder, String library, String name = null) throws IOException { | ||
def libraryPath = new File(library) | ||
if (!libraryPath.exists() || !libraryPath.isDirectory()) { | ||
throw new Error("Library path does not exist or it is not a directory: ${library}") | ||
} | ||
def libraryName = name ?: libraryPath.name | ||
def scm = new FSSCM(libraryPath.absolutePath, false, false, null) | ||
LibraryConfiguration lc = new LibraryConfiguration(libraryName, new SCMRetriever(scm)) | ||
lc.with { | ||
implicit = true | ||
defaultVersion = "master" | ||
} | ||
folder.addProperty(new FolderLibraries([lc])) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package scripts | ||
// Initializes the Development folder, which is fully configurable by the user | ||
|
||
import groovy.io.FileType | ||
import com.synopsys.arc.jenkins.plugins.ownership.OwnershipDescription | ||
import io.jenkins.systemgroovy.plugins.PipelineHelper | ||
import jenkins.model.Jenkins | ||
import com.cloudbees.hudson.plugins.folder.Folder | ||
import org.jenkinsci.plugins.ownership.model.folders.FolderOwnershipHelper | ||
|
||
println("=== Initialize the Demo folder") | ||
if (Jenkins.instance.getItem("Demo") != null) { | ||
println("Demo folder has been already initialized, skipping the step") | ||
return | ||
} | ||
|
||
// Admin owns the root Development folder | ||
def demoFolder = Jenkins.instance.createProject(Folder.class, "Demo") | ||
demoFolder.description = "Demo Pipeline jobs" | ||
FolderOwnershipHelper.setOwnership(demoFolder, new OwnershipDescription(true, "user")) | ||
|
||
// Create a library for local Jenkins Pipeline Library Development | ||
// if the Env Var is set and the directory is mapped | ||
println("==== Initializing local Pipeline Library development dir") | ||
File pipelineLibSource = new File("/var/jenkins_home/pipeline-library/") | ||
if (!new File(pipelineLibSource, "vars").exists()) { // TODO: Lame, to be fixed | ||
println("/var/jenkins_home/pipeline-library is not mapped, skipping") | ||
} else { | ||
println("/var/jenkins_home/pipeline-library is mapped, initializing the directory") | ||
PipelineHelper.addLocalLibrary(demoFolder, pipelineLibSource.absolutePath) | ||
} | ||
|
||
// Loads demo from sources | ||
def demoSourceDir = new File(Jenkins.instance.rootDir, "init.groovy.d/demo") | ||
if (demoSourceDir.exists()) { | ||
println("===== Loading demo") | ||
demoSourceDir.eachFile(FileType.FILES) { file -> | ||
if (file.name.endsWith('.groovy')) { | ||
PipelineHelper.createDemo(file, demoFolder, file.name, false) | ||
} | ||
} | ||
|
||
// Also load demo from the Pipeline library | ||
def libDemos = new File(pipelineLibSource, "demo") | ||
if (libDemos.exists()) { | ||
libDemos.eachFile(FileType.FILES) { file -> | ||
if (file.name.endsWith('.groovy')) { | ||
PipelineHelper.createDemo(file, demoFolder) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters