Skip to content

Jenkins

docker-compose

yaml
version: '3.1'
services:
  jenkins:
    restart: always
    image: jenkinsci/jenkins
    container_name: jenkins
    ports:
      - 8080:8080
      - 50000:50000
    environment:
      TZ: Asia/Shanghai
    volumes:
      - ./data:/var/jenkins_home

权限不足情况

chmod 777 docker-compose.yml
chmod 777 data/

解锁 Jenkins

Jenkins 第一次启动时需要输入一个初始密码用以解锁安装流程,使用 docker logs jenkins 即可方便的查看到初始密码

docker exec -it jenkins bin/bash

修改JDK路径和Apache maven路径

进入容器后生成ssh key

jenkins@b55d5c5faad1:~/jobs/test$ ssh-keygen -t rsa -C "mirrorming@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/var/jenkins_home/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /var/jenkins_home/.ssh/id_rsa.
Your public key has been saved in /var/jenkins_home/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:6WlQ1IeyIyKBBsvU49RVtjftcWJH+Dw8J7HprRlD/9w mirrorming@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|oo. . ..o+ .  .. |
|+o.+ . .o + o.o  |
|o.o..   .+ + =+* |
|  ... ..o.. + X*.|
|   . ...S.   + ++|
|       o .    + o|
|        +      *o|
|       .      o E|
|                 |
+----[SHA256]-----+



cat .ssh/id_rsa.pub
def ver_keys = [ 'bash', '-c', 'cd /var/jenkins_home/jobs/pocket-eureka/workspace;git pull>/dev/null; git remote prune origin >/dev/null; git tag -l|sort -r |head -10 ' ]
ver_keys.execute().text.tokenize('\n')
echo $RELEASE_VERSION
cd /var/jenkins_home/jobs/pocket-eureka/workspace
git checkout $RELEASE_VERSION
git pull origin $RELEASE_VERSION
mvn clean package
cd /usr/local/jenkins/pocket-eureka
kill -9 $(lsof -i:8061 | tail -1|awk '"$1"!=""{print $2}')
source /etc/profile
java -jar target/pocket-eureka-1.0.0-SNAPSHOT.jar &

文章来源于自己总结和网络转载,内容如有任何问题,请大佬斧正!联系我