Skip to content

Commit 1f6bbdc

Browse files
authored
Feature/new improvements (devonfw#102)
devonfw#100: small fix to better support path with whitespaces devonfw#46: added Jenkins-Support
1 parent 9196abb commit 1f6bbdc

File tree

5 files changed

+171
-2
lines changed

5 files changed

+171
-2
lines changed

Jenkinsfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pipeline {
2+
agent any
3+
stages {
4+
stage('Build') {
5+
steps {
6+
sh 'mvn clean install'
7+
}
8+
}
9+
}
10+
}

scripts/src/main/resources/scripts/command/gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function doSetProjectVersion() {
3636
# TODO
3737
if [ -f gradle.properties ]
3838
then
39-
39+
echo TODO
4040
fi
4141
}
4242

scripts/src/main/resources/scripts/command/java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function doSetup() {
3838
fi
3939
if [ -n "${1}" ]
4040
then
41-
doRunCommand "${JAVA_HOME}/bin/java -version" "verify installation of Java"
41+
doRunCommand "'${JAVA_HOME}/bin/java' -version" "verify installation of Java"
4242
fi
4343
}
4444

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env bash
2+
source "$(dirname "${0}")"/../functions
3+
4+
# $1: optional setup
5+
function doSetup() {
6+
if [ -d "${JENKINS_HOME}" ]
7+
then
8+
if [ -n "${1}" ]
9+
then
10+
echo "Jenkins is already installed at ${JENKINS_HOME}"
11+
fi
12+
else
13+
local download_url
14+
if [ -z "${JENKINS_VERSION}" ]
15+
then
16+
download_url="http://mirrors.jenkins.io/war-stable/latest/jenkins.war"
17+
else
18+
download_url="http://ftp-nyc.osuosl.org/pub/jenkins/war-stable/${JENKINS_VERSION}/jenkins.war"
19+
fi
20+
doDownload "${download_url}"
21+
22+
http://localhost:9999/jnlpJars/jenkins-cli.jar
23+
mkdir -p "${JENKINS_HOME}"
24+
doRunCommand "mv ~/Downloads/jenkins.war '${JENKINS_HOME}/jenkins.war'"
25+
local cwd="${PWD}"
26+
cd "${JENKINS_HOME}"
27+
doRunCommand "jar xf jenkins.war WEB-INF/jenkins-cli.jar"
28+
cd "${cwd}"
29+
fi
30+
if [ -n "${1}" ]
31+
then
32+
doRunCommand "java -jar '${JENKINS_HOME}/jenkins.war' --version" "verify installation of Jenkins"
33+
fi
34+
}
35+
36+
function doStart() {
37+
doSetup
38+
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.' &"
39+
sleep 15
40+
echo
41+
echo "Jenkins is running on http://localhost:${JENKINS_PORT:-9999}"
42+
}
43+
44+
function doJenkinsCli() {
45+
echo java -jar "${JENKINS_HOME}/jenkins-cli.jar" -s http://localhost:${JENKINS_PORT:-9999} -auth "${JENKINS_ADMIN_LOGIN:-admin}:${JENKINS_ADMIN_PASSWORD:-admin}" ${@}
46+
java -jar "${JENKINS_HOME}/jenkins-cli.jar" -s http://localhost:${JENKINS_PORT:-9999} -auth "${JENKINS_ADMIN_LOGIN:-admin}:${JENKINS_ADMIN_PASSWORD:-admin}" ${@}
47+
}
48+
49+
function doStop() {
50+
doJenkinsCli shutdown
51+
}
52+
53+
function doAdd() {
54+
if [ ! -d .git ]
55+
then
56+
doFail "Not in a top-level git project!"
57+
fi
58+
local JENKINSFILE="${1:-Jenkinsfile}"
59+
if [ ! -f "${JENKINSFILE}" ]
60+
then
61+
doFail "Could not find Jenkinsfile (${JENKINSFILE})."
62+
fi
63+
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})"
64+
}
65+
66+
function doRemove() {
67+
doJenkinsCli delete-job "$(basename ${PWD})"
68+
}
69+
70+
# CLI
71+
JENKINS_HOME="${DEVON_IDE_HOME}/software/jenkins"
72+
if [ "${1}" = "-h" ] || [ "${1}" = "help" ]
73+
then
74+
echo "Setup or run Jenkins CI build server on local machnine."
75+
echo
76+
echo "Arguments:"
77+
echo " start start local Jenkins server"
78+
echo " stop stop local Jenkins server"
79+
echo " setup setup Jenkins (install, verify, configure)"
80+
echo " add add CI job for current project to Jenkins"
81+
echo " remove remove CI job for current project from Jenkins"
82+
echo
83+
echo "Options:"
84+
elif [ "${1}" = "setup" ]
85+
then
86+
doSetup setup
87+
elif [ "${1}" = "start" ]
88+
then
89+
doStart
90+
elif [ "${1}" = "stop" ]
91+
then
92+
doStop
93+
elif [ "${1}" = "add" ]
94+
then
95+
doAdd
96+
elif [ "${1}" = "remove" ]
97+
then
98+
doRemove
99+
else
100+
doFail "undefined argument ${@}"
101+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version='1.1' encoding='UTF-8'?>
2+
<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch@latest">
3+
<actions/>
4+
<description></description>
5+
<properties>
6+
<org.jenkinsci.plugins.pipeline.modeldefinition.config.FolderConfig plugin="pipeline-model-definition@latest">
7+
</org.jenkinsci.plugins.pipeline.modeldefinition.config.FolderConfig>
8+
</properties>
9+
<folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api@latest">
10+
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
11+
</folderViews>
12+
<healthMetrics>
13+
<com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric plugin="[email protected]">
14+
<nonRecursive>false</nonRecursive>
15+
</com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric>
16+
</healthMetrics>
17+
<icon class="jenkins.branch.MetadataActionFolderIcon" plugin="[email protected]">
18+
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
19+
</icon>
20+
<orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder@latest">
21+
<pruneDeadBranches>true</pruneDeadBranches>
22+
<daysToKeep>-1</daysToKeep>
23+
<numToKeep>-1</numToKeep>
24+
</orphanedItemStrategy>
25+
<triggers/>
26+
<disabled>false</disabled>
27+
<sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api@latest">
28+
<data>
29+
<jenkins.branch.BranchSource>
30+
<source class="jenkins.plugins.git.GitSCMSource" plugin="git@latest">
31+
<id>@UUID@</id>
32+
<remote>@GIT@</remote>
33+
<credentialsId></credentialsId>
34+
<traits>
35+
<jenkins.plugins.git.traits.BranchDiscoveryTrait/>
36+
<jenkins.plugins.git.traits.SubmoduleOptionTrait>
37+
<extension class="hudson.plugins.git.extensions.impl.SubmoduleOption">
38+
<disableSubmodules>false</disableSubmodules>
39+
<recursiveSubmodules>true</recursiveSubmodules>
40+
<trackingSubmodules>false</trackingSubmodules>
41+
<reference></reference>
42+
<parentCredentials>false</parentCredentials>
43+
</extension>
44+
</jenkins.plugins.git.traits.SubmoduleOptionTrait>
45+
</traits>
46+
</source>
47+
<strategy class="jenkins.branch.DefaultBranchPropertyStrategy">
48+
<properties class="empty-list"/>
49+
</strategy>
50+
</jenkins.branch.BranchSource>
51+
</data>
52+
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
53+
</sources>
54+
<factory class="org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory">
55+
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
56+
<scriptPath>Jenkinsfile</scriptPath>
57+
</factory>
58+
</org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject>

0 commit comments

Comments
 (0)