Jenkins系统搭建及常见操作

Posted by zhida on October 22, 2015

This document is not completed and will be updated anytime.

搭建

Dockerfile
FROM ubuntu:14.04

RUN apt-get update
RUN apt-get install -y python-software-properties software-properties-common

RUN \
  echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
  add-apt-repository -y ppa:webupd8team/java && \
  apt-get update && \
  apt-get install -y oracle-java7-installer && \
  rm -rf /var/lib/apt/lists/* && \
  rm -rf /var/cache/oracle-jdk7-installer

# Define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/java-7-oracle

RUN apt-get update
RUN apt-get install -y git curl

RUN curl -Lks http://mirrors.jenkins-ci.org/war/latest/jenkins.war -o /opt/jenkins.war
RUN chmod 644 /opt/jenkins.war
ENV JENKINS_HOME /jenkins

RUN curl -Lks http://www.eu.apache.org/dist/maven/maven-3/3.3.3/binaries/apache-maven-3.3.3-bin.tar.gz -o /opt/apache-maven-3.3.3-bin.tar.gz
RUN tar -xzvf /opt/apache-maven-3.3.3-bin.tar.gz
ADD settings.xml /apache-maven-3.3.3/settings.xml

ENTRYPOINT ["java", "-jar", "/opt/jenkins.war"]
EXPOSE 8080
CMD [""]
docker-compose.yml
jenkins:
  #image: aespinosa/jenkins:latest
  build: ./
  ports:
    - "127.0.0.1:8081:8080"
  environment:
    VIRTUAL_HOST: ci.paraller.com
  volumes:
    - /etc/localtime:/etc/localtime:ro
    - /etc/timezone:/etc/timezone:ro
    - /var/run/docker.sock:/var/run/docker.sock
    - /usr/bin/docker:/usr/bin/docker
    - /root/docker-data/jenkins:/jenkins

常见操作

忘记管理员密码
## 进入相应的文件夹
cd /root/docker-data/jenkins
cd users
cd admin 

## 修改为下面数值 默认密码111111
vim config.xml 
<passwordHash>#jbcrypt:$2a$10$DdaWzN64JgUtLdvxWIflcuQu2fgrrMSAMabF5TSrGK5nXitqK9ZMS</passwordHash>

## 重启Jenkins
docker restart jenkins_jenkins_1