1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-03 15:02:35 +02:00

Switch to jenkins file runner approach

This commit is contained in:
Marcus Holl 2019-05-17 15:41:00 +02:00
parent a24c89ce12
commit 4cae7b9ace
2 changed files with 33 additions and 25 deletions

View File

@ -3,6 +3,18 @@ import groovy.json.JsonSlurper
import jenkins.model.Jenkins 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 resolvePlugins() {
def stepCallMapping = new JsonSlurper().parseText(new File(System.getenv()['calls']).text) def stepCallMapping = new JsonSlurper().parseText(new File(System.getenv()['calls']).text)
@ -43,11 +55,3 @@ def resolvePlugin(call) {
} }
return null return null
} }
try {
resolvePlugins()
} catch(Exception e) {
def result = System.getenv()['result']
new File(new File(result).getParentFile(), 'FAILURE').text = ''
throw e
}

View File

@ -3,28 +3,32 @@
mvn clean test mvn clean test
groovy steps.groovy groovy steps.groovy
WS_OUT="$(pwd)/jenkins_workspace"
WS_IN=/workspace
[ -d jenkins_home ] && rm -rf jenkins_home REL_CALLS=calls.json
cp -r jenkins_home_init jenkins_home 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; } [ -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)" docker run \
echo "ContainerId: ${cID}" -w "${WS_IN}" \
while true --env calls="${WS_IN}/${REL_CALLS}" \
do --env result="${WS_IN}/${REL_RESULT}" \
[ -f jenkins_home/piper/result.json ] && { docker rm -f "${cID}"; break; } # normal ... -v "${WS_OUT}:${WS_IN}" \
[ -f jenkins_home/piper/FAILURE ] && { docker rm -f "${cID}"; break; } # executing of our init script failed ppiper/jenkinsfile-runner \
docker ps --no-trunc |grep -q "${cID}"|| break # docker container does not run anymore -ns \
echo "[INFO] waiting for results" -f Jenkinsfile \
sleep 10 --runWorkspace /workspace
done
RESULT="$(pwd)/jenkins_home/piper/result.json" [ -f "${RESULT}" ] && cat "${RESULT}"
[ -f "${RESULT}" ] && cat jenkins_home/piper/result.json