jenkins 節點配置使用小記

雪花飄發表於2019-01-27

jenkins節點容器有兩種,一種是ssh-slave,master使用ssh命令連線節點,另一種是jnlp-slave,節點通過url連線master,以下使用的的是ssl-slave

  • jnlp-slave 使用相關
    https://github.com/jenkinsci/docker-jnlp-s...
  • ssh-slave 使用相關
    https://github.com/jenkinsci/docker-ssh-sl...
  • 拉取 ssh-slave 倉庫程式碼
    https://github.com/jenkinsci/docker-ssh-sl...
  • 二開 Dockerfile 檔案
    
    # The MIT License
    #
    #  Copyright (c) 2015, CloudBees, Inc.
    #
    #  Permission is hereby granted, free of charge, to any person obtaining a copy
    #  of this software and associated documentation files (the "Software"), to deal
    #  in the Software without restriction, including without limitation the rights
    #  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    #  copies of the Software, and to permit persons to whom the Software is
    #  furnished to do so, subject to the following conditions:
    #
    #  The above copyright notice and this permission notice shall be included in
    #  all copies or substantial portions of the Software.
    #
    #  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    #  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    #  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    #  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    #  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    #  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    #  THE SOFTWARE.

FROM openjdk:8-jdk
LABEL MAINTAINER="Nicolas De Loof nicolas.deloof@gmail.com"

ARG user=jenkins
ARG group=jenkins
ARG uid=1000
ARG gid=1000

ARG JENKINS_AGENT_HOME=/var/jenkins_home

ENV JENKINS_AGENT_HOME ${JENKINS_AGENT_HOME}

RUN groupadd -g ${gid} ${group} \
&& useradd -d "${JENKINS_AGENT_HOME}" -u "${uid}" -g "${gid}" -m -s /bin/bash "${user}"

COPY ansible /etc/ansible
COPY pip /root/.pip
COPY Python-3.6.3.tar /usr/local/src/
COPY node-v10.15.0-linux-x64.tar /usr/local/src/

RUN apt-get update \
&& apt-get install --no-install-recommends -y openssh-server \
&& apt-get install -y rsync make gcc zlib openssl libssl-dev vim \
&& cd /usr/local/src \
&& tar -xf Python-3.6.3.tar \
&& cd Python-3.6.3 \
&& ./configure && make && make install \
&& pip3 install cryptography==2.4.2 \
&& pip3 install paramiko \
&& pip3 install ansible==2.3.1.0

RUN cd /usr/local/src \
&& tar xf node-v10.15.0-linux-x64.tar \
&& cp node-v10.15.0-linux-x64 /usr/local/node-v10 -rf \
&& ln -s /usr/local/node-v10/bin/node /usr/local/bin/node \
&& ln -s /usr/local/node-v10/bin/npm /usr/local/bin/npm \
&& npm config set registry https://registry.npm.taobao.org \
&& rm -rf /usr/local/src/ \
&& rm -rf /var/lib/apt/lists/

RUN sed -i "/StrictHostKeyChecking/d" /etc/ssh/ssh_config
RUN echo "StrictHostKeyChecking no" >>/etc/ssh/ssh_config
RUN sed -i /etc/ssh/sshd_config \
-e 's/#PermitRootLogin./PermitRootLogin no/' \
-e 's/#RSAAuthentication.
/RSAAuthentication yes/' \
-e 's/#PasswordAuthentication./PasswordAuthentication no/' \
-e 's/#SyslogFacility.
/SyslogFacility AUTH/' \
-e 's/#LogLevel.*/LogLevel INFO/' && \
mkdir /var/run/sshd

VOLUME "${JENKINS_AGENT_HOME}" "/tmp" "/run" "/var/run"
WORKDIR "${JENKINS_AGENT_HOME}"

COPY setup-sshd /usr/local/bin/setup-sshd

COPY id_rsa "${JENKINS_AGENT_HOME}/.ssh/"
RUN chown -R jenkins.jenkins "${JENKINS_AGENT_HOME}/.ssh"

COPY timezone /etc/

COPY bashrc "${JENKINS_AGENT_HOME}/.bashrc"
RUN chown jenkins.jenkins "${JENKINS_AGENT_HOME}/.bashrc"

EXPOSE 22

ENTRYPOINT ["setup-sshd"]


- 構建映象 docker-compose up -d --build,查詢容器的IP
- 系統管理->節點管理,新增節點,host為slave容器的IP
![在這裡插入圖片描述](https://img-blog.csdnimg.cn/20190127133746361.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjIzMzcyMw==,size_16,color_FFFFFF,t_70)
其中 credentials 設定為jenkins賬號,username 為jenkins,私鑰為jenkins的私鑰
![在這裡插入圖片描述](https://img-blog.csdnimg.cn/2019012713405110.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjIzMzcyMw==,size_16,color_FFFFFF,t_70)
儲存,檢視連線是否成功
![在這裡插入圖片描述](https://img-blog.csdnimg.cn/20190127134254465.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjIzMzcyMw==,size_16,color_FFFFFF,t_70)
本作品採用《CC 協議》,轉載必須註明作者和本文連結

雪花飄

相關文章