本文主要使用時(shí)dockerfile構(gòu)建,主要通過(guò)JaveWeb連接
dockerfile中包含AndroidSdk,F(xiàn)lutterSdk,Jdk11
廢話(huà)不多說(shuō)参袱,先看dockerfile,有注釋
# 基于已有的鏡像 jenkins/inbound-agent 來(lái)構(gòu)建新鏡像
FROM jenkins/inbound-agent
MAINTAINER xxx
USER root
# 暴漏給外部的文件夾(選配,暫時(shí)沒(méi)啥用抹蚀,先寫(xiě)上 萬(wàn)一以后用上了)
VOLUME /file
# 更新容器配置
RUN apt update -y && apt upgrade -y && apt-get install curl && apt install wget unzip -y && apt install -y xz-utils
# 設(shè)置變量
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
# 創(chuàng)建android sdk目錄,并下載 sdkmanager
RUN mkdir -p ${ANDROID_HOME} \
&& cd $ANDROID_HOME \
&& curl -o sdk.zip $SDK_TOOL_URL \
&& unzip sdk.zip \
&& rm sdk.zip
# 設(shè)置環(huán)境變量
RUN echo "export PATH=/var/local/sdk/cmdline-tools/latest/bin" >> ~/.bashrc
RUN echo "export PATH=/bin:/usr/bin:$PATH" >> ~/.bashrc
# 設(shè)置環(huán)境變量: 把 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是因?yàn)榇颂帟?huì)有一個(gè)licence,需要用戶(hù)同意后才會(huì)安裝
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"
# 設(shè)置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"
# 創(chuàng)建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 因?yàn)?默認(rèn)就是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
# 容器構(gòu)建命令
# docker build -t jenkins-agent:1.0.0 -f ./dockerfile .
# 啟動(dòng)容器命令
# 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
通過(guò)dockerfile構(gòu)建容器images鏡像
#容器構(gòu)建命令(jenkins-agent:1.0.0 就是構(gòu)建出來(lái)的docker image名字)
docker build -t jenkins-agent:1.0.0 -f ./dockerfile .
啟動(dòng)容器命令
# 啟動(dòng)容器命令
#詳情 請(qǐng)查看 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節(jié)點(diǎn)配置
新建節(jié)點(diǎn)
節(jié)點(diǎn)名稱(chēng)配置
(??注意剿牺,節(jié)點(diǎn)名稱(chēng)一定要和構(gòu)建容器的名稱(chēng)一樣,文中用的是CenterOS)
節(jié)點(diǎn)基本配置
JDK11環(huán)境變量配置
ANDROID_HOME 已在dockerfile構(gòu)建的時(shí)候設(shè)置了環(huán)境變量 所以無(wú)需配置
Flutter環(huán)境變量暫未配置环壤,我是在任務(wù)構(gòu)建的時(shí)候設(shè)置的環(huán)境變量
export PATH="$PATH:/var/jenkins_home/sdk/flutter/bin"
具體如圖: