Skip to content

Commit f5590e5

Browse files
committed
add warnings for subprocess execution in Java version switch scripts and update script syntax for consistency
1 parent f0d1feb commit f5590e5

5 files changed

Lines changed: 30 additions & 4 deletions

File tree

be-java-springboot/Jenkinsfile.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def stageBuild(def context) {
2626
}
2727
stage('Build and Unit Test') {
2828
withEnv(["TAGVERSION=${context.tagversion}", "NEXUS_HOST=${context.nexusHost}", "NEXUS_USERNAME=${context.nexusUsername}", "NEXUS_PASSWORD=${context.nexusPassword}", "JAVA_OPTS=${javaOpts}","GRADLE_TEST_OPTS=${gradleTestOpts}","ENVIRONMENT=${springBootEnv}"]) {
29-
def status = sh(script: "source use-j25.sh && ./gradlew clean build --stacktrace --no-daemon && source use-j21.sh", returnStatus: true)
29+
def status = sh(script: 'source use-j25.sh && ./gradlew clean build --stacktrace --no-daemon && source use-j21.sh', returnStatus: true)
3030
if (status != 0) {
3131
error "Build failed!"
3232
}

be-scala-play/Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ odsQuickstarterPipeline(
1919
) { context ->
2020

2121
stage("init scala play project") {
22-
sh "source use-j11.sh && sbt -no-colors -v new file://${context.sourceDir}/be-scala-play.g8 --name=${context.componentId} --secret=\$(uuidgen) && source use-j21.sh"
22+
sh 'source use-j11.sh && sbt -no-colors -v new file://${context.sourceDir}/be-scala-play.g8 --name=${context.componentId} --secret=\$(uuidgen) && source use-j21.sh'
2323
}
2424

2525
odsQuickstarterStageCopyFiles(context)

be-scala-play/Jenkinsfile.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ odsComponentPipeline(
2222
def stageBuild(def context) {
2323
stage('Build and Unit Test') {
2424
withEnv(["TAGVERSION=${context.tagversion}"]){
25-
def status = sh(script: "source use-j11.sh && sbt -v clean scalafmtSbtCheck scalafmtCheckAll coverage test coverageReport coverageOff compile:clean copyDockerFiles && source use-j21.sh", returnStatus: true)
25+
def status = sh(script: 'source use-j11.sh && sbt -v clean scalafmtSbtCheck scalafmtCheckAll coverage test coverageReport coverageOff compile:clean copyDockerFiles && source use-j21.sh', returnStatus: true)
2626
if (status != 0) {
2727
error "Build failed!"
2828
}

common/jenkins-agents/scala/docker/use-j11.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,16 @@ else
3636
msg_and_exit "Cannot configure JAVA_HOME environment variable to ${JAVA_HOME}"
3737
fi
3838
echo "JAVA_HOME: $JAVA_HOME"
39+
40+
# If not sourced, print the export command so parent shell can eval it
41+
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
42+
echo ""
43+
echo "================================================================================="
44+
echo "WARNING: Script executed as subprocess - JAVA_HOME will NOT persist!"
45+
echo "-----"
46+
echo "Usage Options:"
47+
echo " Option 1 (source): source ${BASH_SOURCE[0]}"
48+
echo " Option 2 (dot): . ${BASH_SOURCE[0]}"
49+
echo "================================================================================="
50+
echo ""
51+
fi

common/jenkins-agents/scala/docker/use-j17.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,17 @@ if [ -d ${JAVA_HOME}/bin/ ]; then
3535
else
3636
msg_and_exit "Cannot configure JAVA_HOME environment variable to ${JAVA_HOME}"
3737
fi
38-
echo "JAVA_HOME: $JAVA_HOME"
38+
echo "JAVA_HOME: $JAVA_HOME"
39+
40+
# If not sourced, print the export command so parent shell can eval it
41+
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
42+
echo ""
43+
echo "================================================================================="
44+
echo "WARNING: Script executed as subprocess - JAVA_HOME will NOT persist!"
45+
echo "-----"
46+
echo "Usage Options:"
47+
echo " Option 1 (source): source ${BASH_SOURCE[0]}"
48+
echo " Option 2 (dot): . ${BASH_SOURCE[0]}"
49+
echo "================================================================================="
50+
echo ""
51+
fi

0 commit comments

Comments
 (0)