I am trying to import a custom tool into the pipeline Jenkinsfile script (specifically, the Android SDK). From the build console, it says that I need to set the ANDROID_HOME environment variable to build my Android app. However, when I tried adding the SDK download and set it to the ANDROID_HOME variable, it's telling me that the directory does not exist:
Caused by: java.lang.RuntimeException: The SDK directory '/var/jenkins_home/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/Android_SDK_CLI_tools_4333796/bin' does not exist.
In the global tools configuration page, here's how I added the Android SDK:
Name: Android_SDK_CLI_tools_4333796
Tool home: bin
Command: (below)
if [ ! -f "Android_SDK_tools_4333796/" ]; then
echo "curl"
curl -O https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
echo "unzip"
yes | unzip -q sdk-tools-linux-4333796.zip
rm sdk-tools-linux-4333796.zip
echo "licenses"
yes | tools/bin/sdkmanager --licenses
fi
Below is how I set my Jenkinsfile:
pipeline {
agent any
environment {
ANDROID_HOME = tool 'Android_SDK_CLI_tools_4333796'
//ANDROID_HOME = tool name: 'Android_SDK_CLI_tools_4333796', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool' //alternative but still has the same results.
//env.PATH = "${env.PATH}:${androidSDKHome}"
}
tools {
jdk 'JDK_9.0.4'
}
stages {
stage('Pre-build') {
steps {
// seeing if Java JDK installed correctly
sh 'java --version'
print (env.ANDROID_HOME) // prints: /var/jenkins_home/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/Android_SDK_CLI_tools_4333796/bin
}
}
stage('Test') {
steps {
echo 'Testing stage...'
sh './gradlew clean --stacktrace' //ERROR (above)
}
}
}
}
My question is, am I pulling in this custom tool into the build properly? It seems Jenkins can't find it the custom tool even though I trying to access the absolute path.
I tried referencing this SO question; However, this is for me to obtain the executable whereas I'm looking to set the env var for Gradle to pick up the ANDROID_HOME env var automatically.