本文主要使用时dockerfile构建,主要通过JaveWeb连接
dockerfile中包含AndroidSdk,FlutterSdk,Jdk11
废话不多说,先看dockerfile,有注释
# 基于已有的镜像 jenkins/inbound-agent 来构建新镜像
FROM jenkins/inbound-agent
MAINTAINER xxx
USER root
# 暴漏给外部的文件夹(选配,暂时没啥用,先写上 万一以后用上了)
VOLUME /file
# 更新容器配置
RUN apt update -y && apt upgrade -y && apt-get install curl && apt install wget unzip -y && apt install -y xz-utils
# 设置变量
ENV USR_LOCAL="/opt"
ENV ANDROID_HOME="${USR_LOCAL}/android" \
SDK_TOOL_URL="https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip
#https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip
# 创建android sdk目录,并下载 sdkmanager
RUN mkdir -p ${ANDROID_HOME} \
&& cd $ANDROID_HOME \
&& curl -o sdk.zip $SDK_TOOL_URL \
&& unzip sdk.zip \
&& rm sdk.zip
# 设置环境变量
RUN echo "export PATH=/var/local/sdk/cmdline-tools/latest/bin" >> ~/.bashrc
RUN echo "export PATH=/bin:/usr/bin:$PATH" >> ~/.bashrc
# 设置环境变量: 把 android sdk 路径加入到 PATH 中
ENV PATH ${ANDROID_HOME}/cmdline-tools/latest:${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools:${PATH}
# 安装android sdk其他package, 输入y是因为此处会有一个licence,需要用户同意后才会安装
RUN echo y | ${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager "platform-tools" "platforms;android-28" "build-tools;28.0.3" "ndk-bundle" "cmake;3.6.4111459"
# 设置Flutter变量
ENV FLUTTER_HOME="${USR_LOCAL}/flutter" \
FLUTTER_SDK_TOOL_URL="https://storage.flutter-io.cn/flutter_infra_release/releases/stable/linux/flutter_linux_3.3.2-stable.tar.xz"
# 创建Flutter sdk目录,并解压
RUN mkdir -p ${FLUTTER_HOME} \
&& cd $FLUTTER_HOME \
&& curl -o flutter_sdk.tar.xz $FLUTTER_SDK_TOOL_URL \
&& tar -xvf flutter_sdk.tar.xz \
&& rm flutter_sdk.tar.xz
RUN echo "export PATH=/opt/flutter/bin" >> ~/.bashrc
# 不需要jdk11 因为 默认就是jdk11
# ENV JDK11_HOME="${USR_LOCAL}/jdk11" \
# JDK11_TOOL_URL="http://192.168.31.32:8011/api/public/dl/gwtAZD1K"
# RUN mkdir -p ${JDK11_HOME} \
# && cd $JDK11_HOME \
# && curl -o jdk11.tar.gz $JDK11_TOOL_URL \
# && tar -xvf jdk11.tar.gz \
# && rm jdk11.tar.gz
# 容器构建命令
# docker build -t jenkins-agent:1.0.0 -f ./dockerfile .
# 启动容器命令
# docker run -itd --name jenkins-agent -u root jenkins-agent:1.0.0 -url http://192.168.31.32:8090 -workDir=/Users/xxx/Downloads/docker/jenkins 6e40d2862ffdb18ec2bf3884c7f712fxxxxxxxxxxxxxxxxxxxx CenterOS
通过dockerfile构建容器images镜像
#容器构建命令(jenkins-agent:1.0.0 就是构建出来的docker image名字)
docker build -t jenkins-agent:1.0.0 -f ./dockerfile .
启动容器命令
# 启动容器命令
#详情 请查看 https://hub.docker.com/r/jenkins/inbound-agent
docker run -itd --name jenkins-agent -u root jenkins-agent:1.0.0 -url http://192.168.31.32:8090 -workDir=/Users/xxx/Downloads/docker/jenkins 6e40d2862ffdb18ec2bf3884c7f712fxxxxxxxxxxxxxxxxxxxx CenterOS
Jenkins节点配置
新建节点
节点名称配置
(⚠️注意,节点名称一定要和构建容器的名称一样,文中用的是CenterOS)
节点基本配置
JDK11环境变量配置
ANDROID_HOME 已在dockerfile构建的时候设置了环境变量 所以无需配置
Flutter环境变量暂未配置,我是在任务构建的时候设置的环境变量
export PATH="$PATH:/var/jenkins_home/sdk/flutter/bin"
具体如图: