Skip to content

Commit

Permalink
Feature/new improvements (#102)
Browse files Browse the repository at this point in the history
#100: small fix to better support path with whitespaces
#46: added Jenkins-Support
  • Loading branch information
hohwille authored May 3, 2019
1 parent 9196abb commit 1f6bbdc
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'mvn clean install'
}
}
}
}
2 changes: 1 addition & 1 deletion scripts/src/main/resources/scripts/command/gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function doSetProjectVersion() {
# TODO
if [ -f gradle.properties ]
then

echo TODO
fi
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/src/main/resources/scripts/command/java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function doSetup() {
fi
if [ -n "${1}" ]
then
doRunCommand "${JAVA_HOME}/bin/java -version" "verify installation of Java"
doRunCommand "'${JAVA_HOME}/bin/java' -version" "verify installation of Java"
fi
}

Expand Down
101 changes: 101 additions & 0 deletions scripts/src/main/resources/scripts/command/jenkins
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env bash
source "$(dirname "${0}")"/../functions

# $1: optional setup
function doSetup() {
if [ -d "${JENKINS_HOME}" ]
then
if [ -n "${1}" ]
then
echo "Jenkins is already installed at ${JENKINS_HOME}"
fi
else
local download_url
if [ -z "${JENKINS_VERSION}" ]
then
download_url="http://mirrors.jenkins.io/war-stable/latest/jenkins.war"
else
download_url="http://ftp-nyc.osuosl.org/pub/jenkins/war-stable/${JENKINS_VERSION}/jenkins.war"
fi
doDownload "${download_url}"

http://localhost:9999/jnlpJars/jenkins-cli.jar
mkdir -p "${JENKINS_HOME}"
doRunCommand "mv ~/Downloads/jenkins.war '${JENKINS_HOME}/jenkins.war'"
local cwd="${PWD}"
cd "${JENKINS_HOME}"
doRunCommand "jar xf jenkins.war WEB-INF/jenkins-cli.jar"
cd "${cwd}"
fi
if [ -n "${1}" ]
then
doRunCommand "java -jar '${JENKINS_HOME}/jenkins.war' --version" "verify installation of Jenkins"
fi
}

function doStart() {
doSetup
doRunCommand "java -jar '${JENKINS_HOME}/jenkins.war' --httpPort=${JENKINS_PORT:-9999} ${JENKINS_OPTS} || echo -e 'Jenkins could not be started.\nIf you see \"Address already in use\" error above this only means it was already running.' &"
sleep 15
echo
echo "Jenkins is running on http://localhost:${JENKINS_PORT:-9999}"
}

function doJenkinsCli() {
echo java -jar "${JENKINS_HOME}/jenkins-cli.jar" -s http://localhost:${JENKINS_PORT:-9999} -auth "${JENKINS_ADMIN_LOGIN:-admin}:${JENKINS_ADMIN_PASSWORD:-admin}" ${@}
java -jar "${JENKINS_HOME}/jenkins-cli.jar" -s http://localhost:${JENKINS_PORT:-9999} -auth "${JENKINS_ADMIN_LOGIN:-admin}:${JENKINS_ADMIN_PASSWORD:-admin}" ${@}
}

function doStop() {
doJenkinsCli shutdown
}

function doAdd() {
if [ ! -d .git ]
then
doFail "Not in a top-level git project!"
fi
local JENKINSFILE="${1:-Jenkinsfile}"
if [ ! -f "${JENKINSFILE}" ]
then
doFail "Could not find Jenkinsfile (${JENKINSFILE})."
fi
cat "${DEVON_IDE_HOME}/scripts/templates/jenkins/project.xml" | sed "s~@GIT@~file://${PWD}~" | sed "s~@UUID@~$(head -c 20 /dev/random | base64)~" | java -jar "${JENKINS_HOME}/jenkins-cli.jar" -s http://localhost:${JENKINS_PORT:-9999} -auth "${JENKINS_ADMIN_LOGIN:-admin}:${JENKINS_ADMIN_PASSWORD:-admin}" create-job "$(basename ${PWD})"
}

function doRemove() {
doJenkinsCli delete-job "$(basename ${PWD})"
}

# CLI
JENKINS_HOME="${DEVON_IDE_HOME}/software/jenkins"
if [ "${1}" = "-h" ] || [ "${1}" = "help" ]
then
echo "Setup or run Jenkins CI build server on local machnine."
echo
echo "Arguments:"
echo " start start local Jenkins server"
echo " stop stop local Jenkins server"
echo " setup setup Jenkins (install, verify, configure)"
echo " add add CI job for current project to Jenkins"
echo " remove remove CI job for current project from Jenkins"
echo
echo "Options:"
elif [ "${1}" = "setup" ]
then
doSetup setup
elif [ "${1}" = "start" ]
then
doStart
elif [ "${1}" = "stop" ]
then
doStop
elif [ "${1}" = "add" ]
then
doAdd
elif [ "${1}" = "remove" ]
then
doRemove
else
doFail "undefined argument ${@}"
fi
58 changes: 58 additions & 0 deletions scripts/src/main/resources/scripts/templates/jenkins/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version='1.1' encoding='UTF-8'?>
<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch@latest">
<actions/>
<description></description>
<properties>
<org.jenkinsci.plugins.pipeline.modeldefinition.config.FolderConfig plugin="pipeline-model-definition@latest">
</org.jenkinsci.plugins.pipeline.modeldefinition.config.FolderConfig>
</properties>
<folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api@latest">
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
</folderViews>
<healthMetrics>
<com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric plugin="[email protected]">
<nonRecursive>false</nonRecursive>
</com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric>
</healthMetrics>
<icon class="jenkins.branch.MetadataActionFolderIcon" plugin="[email protected]">
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
</icon>
<orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder@latest">
<pruneDeadBranches>true</pruneDeadBranches>
<daysToKeep>-1</daysToKeep>
<numToKeep>-1</numToKeep>
</orphanedItemStrategy>
<triggers/>
<disabled>false</disabled>
<sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api@latest">
<data>
<jenkins.branch.BranchSource>
<source class="jenkins.plugins.git.GitSCMSource" plugin="git@latest">
<id>@UUID@</id>
<remote>@GIT@</remote>
<credentialsId></credentialsId>
<traits>
<jenkins.plugins.git.traits.BranchDiscoveryTrait/>
<jenkins.plugins.git.traits.SubmoduleOptionTrait>
<extension class="hudson.plugins.git.extensions.impl.SubmoduleOption">
<disableSubmodules>false</disableSubmodules>
<recursiveSubmodules>true</recursiveSubmodules>
<trackingSubmodules>false</trackingSubmodules>
<reference></reference>
<parentCredentials>false</parentCredentials>
</extension>
</jenkins.plugins.git.traits.SubmoduleOptionTrait>
</traits>
</source>
<strategy class="jenkins.branch.DefaultBranchPropertyStrategy">
<properties class="empty-list"/>
</strategy>
</jenkins.branch.BranchSource>
</data>
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
</sources>
<factory class="org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory">
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
<scriptPath>Jenkinsfile</scriptPath>
</factory>
</org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject>

0 comments on commit 1f6bbdc

Please sign in to comment.