mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
Switch to jenkins file runner approach
This commit is contained in:
parent
a24c89ce12
commit
4cae7b9ace
@ -3,6 +3,18 @@ import groovy.json.JsonSlurper
|
||||
|
||||
import jenkins.model.Jenkins
|
||||
|
||||
node() {
|
||||
stage('Resolve Plugins') {
|
||||
try {
|
||||
resolvePlugins()
|
||||
} catch(Exception e) {
|
||||
def result = System.getenv()['result']
|
||||
new File(new File(result).getParentFile(), 'FAILURE').text = "${e.getMessage()}"
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def resolvePlugins() {
|
||||
def stepCallMapping = new JsonSlurper().parseText(new File(System.getenv()['calls']).text)
|
||||
|
||||
@ -43,11 +55,3 @@ def resolvePlugin(call) {
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
try {
|
||||
resolvePlugins()
|
||||
} catch(Exception e) {
|
||||
def result = System.getenv()['result']
|
||||
new File(new File(result).getParentFile(), 'FAILURE').text = ''
|
||||
throw e
|
||||
}
|
@ -3,28 +3,32 @@
|
||||
mvn clean test
|
||||
groovy steps.groovy
|
||||
|
||||
WS_OUT="$(pwd)/jenkins_workspace"
|
||||
WS_IN=/workspace
|
||||
|
||||
[ -d jenkins_home ] && rm -rf jenkins_home
|
||||
cp -r jenkins_home_init jenkins_home
|
||||
REL_CALLS=calls.json
|
||||
REL_RESULT=result.json
|
||||
|
||||
CALLS="$(pwd)/jenkins_home/piper/calls.json"
|
||||
CALLS="${WS_OUT}/${REL_CALLS}"
|
||||
RESULT="${WS_OUT}/${REL_RESULT}"
|
||||
|
||||
mkdir -p $(dirname "${CALLS}")
|
||||
for f in ${CALLS} ${RESULT}
|
||||
do
|
||||
[ -e "${f}" ] && rm -rf "${f}"
|
||||
done
|
||||
|
||||
mv target/performedCalls.json "${CALLS}"
|
||||
cp target/performedCalls.json "${CALLS}"
|
||||
|
||||
[ -f "${CALLS}" ] || { echo "File \"${CALLS}\" does not exist." ; exit 1; }
|
||||
|
||||
cID="$(docker run -d -v `pwd`/jenkins_home:/var/jenkins_home --env calls=/var/jenkins_home/piper/calls.json --env result=/var/jenkins_home/piper/result.json ppiper/jenkins-master)"
|
||||
echo "ContainerId: ${cID}"
|
||||
while true
|
||||
do
|
||||
[ -f jenkins_home/piper/result.json ] && { docker rm -f "${cID}"; break; } # normal ...
|
||||
[ -f jenkins_home/piper/FAILURE ] && { docker rm -f "${cID}"; break; } # executing of our init script failed
|
||||
docker ps --no-trunc |grep -q "${cID}"|| break # docker container does not run anymore
|
||||
echo "[INFO] waiting for results"
|
||||
sleep 10
|
||||
done
|
||||
docker run \
|
||||
-w "${WS_IN}" \
|
||||
--env calls="${WS_IN}/${REL_CALLS}" \
|
||||
--env result="${WS_IN}/${REL_RESULT}" \
|
||||
-v "${WS_OUT}:${WS_IN}" \
|
||||
ppiper/jenkinsfile-runner \
|
||||
-ns \
|
||||
-f Jenkinsfile \
|
||||
--runWorkspace /workspace
|
||||
|
||||
RESULT="$(pwd)/jenkins_home/piper/result.json"
|
||||
[ -f "${RESULT}" ] && cat jenkins_home/piper/result.json
|
||||
[ -f "${RESULT}" ] && cat "${RESULT}"
|
||||
|
Loading…
Reference in New Issue
Block a user