I'm trying to setup Jenkins slave using Kubernetes using kubernetes plugin. My goal is to have the plugin spin up a GKE container each time there is a job need to run.
I have done the below setup:
1 - create new cluster
2 - create service account with admin role for the cluster
3 - config jenkins kubernetes
plugin (able to connect to GKE cluster)
4 - config pod template
(using my custom Docker image which is already pushed to DockerHub)
When I build a project I can see the job running halfway until get to the point below:
Agent went offline during the build
ERROR: Connection was broken: java.nio.channels.ClosedChannelException
What is this error and how can I fix it? Is there any other setup needed?
Updated: after searching, I updated my Dockerfile
. Seems like the container can write already:
FROM jenkins/inbound-agent
USER root
# Install Build Essentials
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get dist-upgrade -y \
&& apt-get install build-essential -y
# Set Environment Variables
ENV SDK_URL="https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip" \
ANDROID_HOME="/home/jenkins/android-sdk" \
ANDROID_VERSION=30 \
BUILDTOOL_VERSION="30.0.2" \
NDK_VERSION="22.0.7026061"
USER jenkins
# Download Android SDK
RUN mkdir "$ANDROID_HOME" .android \
&& cd "$ANDROID_HOME" \
&& curl -o sdk.zip $SDK_URL \
&& unzip sdk.zip \
&& rm sdk.zip \
&& mkdir "$ANDROID_HOME/licenses" || true \
&& echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_HOME/licenses/android-sdk-license" \
&& yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses
# Install Android Build Tool and Libraries
RUN $ANDROID_HOME/tools/bin/sdkmanager --update
RUN $ANDROID_HOME/tools/bin/sdkmanager "build-tools;${BUILDTOOL_VERSION}" \
"platforms;android-${ANDROID_VERSION}" \
"platform-tools" \
"ndk;${NDK_VERSION}"
I can see the Workload
created and build running but don't see why it always stop at the middle with the error above. It seems my pod is disconnected before build finish.