配置DockerInDocker
在宁城等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站建设、成都网站制作 网站设计制作按需求定制开发,公司网站建设,企业网站建设,高端网站设计,全网整合营销推广,成都外贸网站建设,宁城网站建设费用合理。
配置JenkinsMaster挂载Docker
- docker run --name jenkins -itd \
- -p 8081:8080 \
- -p 50000:50000 \
- -v ~/jenkins:/var/jenkins_home \
- -v /var/run/docker.sock:/var/run/docker.sock \
- -v /usr/local/bin/docker:/usr/bin/docker \
- jenkins/jenkins:lts
解决权限问题/以root用户运行
- docker exec -it -u root jenkins bash
- usermod -aG root jenkins
- id jenkins
- uid=1000(jenkins) gid=1000(jenkins) groups=1000(jenkins),0(root),1(daemon)
调试流水线
- pipeline {
- agent {
- docker {
- image 'maven:3.6.3-jdk-8'
- args '-v $HOME/.m2:/root/.m2'
- }
- }
- stages {
- stage('Build') {
- steps {
- sh 'mvn -v'
- }
- }
- }
- }
- Started by user admin
- Replayed #40
- Running in Durability level: MAX_SURVIVABILITY
- [Pipeline] Start of Pipeline
- [Pipeline] node
- Running on Jenkins in /var/jenkins_home/workspace/test
- [Pipeline] {
- [Pipeline] isUnix
- [Pipeline] sh
- + docker inspect -f . maven:3.6.3-jdk-8
- .
- [Pipeline] withDockerContainer
- Jenkins seems to be running inside container 5373edddcdadb63df5e5c6ed7f6149719ad749536242f10c06cbceca511a9898
- $ docker run -t -d -u 1000:1000 -w /var/jenkins_home/workspace/test --volumes-from 5373edddcdadb63df5e5c6ed7f6149719ad749536242f10c06cbceca511a9898 -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** maven:3.6.3-jdk-8 cat
- $ docker top 01102f26f8957fc7c46d0f9d1118e38316e313707357cdc5332c7d62836e1df2 -eo pid,comm
- [Pipeline] {
- [Pipeline] stage
- [Pipeline] { (Test)
- [Pipeline] sh
- + mvn -v
- Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
- Maven home: /usr/share/maven
- Java version: 1.8.0_242, vendor: Oracle Corporation, runtime: /usr/local/openjdk-8/jre
- Default locale: en, platform encoding: UTF-8
- OS name: "linux", version: "4.19.76-linuxkit", arch: "amd64", family: "unix"
- [Pipeline] }
- [Pipeline] // stage
- [Pipeline] }
- $ docker stop --time=1 01102f26f8957fc7c46d0f9d1118e38316e313707357cdc5332c7d62836e1df2
- $ docker rm -f 01102f26f8957fc7c46d0f9d1118e38316e313707357cdc5332c7d62836e1df2
- [Pipeline] // withDockerContainer
- [Pipeline] }
- [Pipeline] // node
- [Pipeline] End of Pipeline
- Finished: SUCCESS
每个阶段指定不同的Docker容器运行
- pipeline {
- agent none
- stages {
- stage('ServiceBuild') {
- agent {
- docker {
- image 'maven:3.6.3-jdk-8'
- args '-v $HOME/.m2:/root/.m2'
- }
- }
- steps {
- sh 'mvn -v && sleep 15'
- }
- }
- stage('WebBuild') {
- agent {
- docker {
- image 'node:7-alpine'
- args '-v $HOME/.m2:/root/.m2'
- }
- }
- steps {
- sh 'node -v && sleep 15'
- }
- }
- }
- }
前端流水线
- pipeline {
- agent none
- stages {
- stage('WebBuild') {
- agent {
- docker {
- image 'node:10.19.0-alpine'
- args '-u 0:0 -v /var/jenkins_home/.npm:/root/.npm'
- }
- }
- steps {
- sh """
- id
- ls /root/.npm
- ls /root/ -a
- npm config set unsafe-perm=true
- npm config list
- npm config set cache /root/.npm
- #npm config set registry https://registry.npm.taobao.org
- npm config list
- ls
- npm install --unsafe-perm=true && npm run build && ls -l dist/ && sleep 15
- """
- }
- }
- }
- }
FAQ
npm构建权限问题:使用root用户构建。设置容器运行用户 -u 0:0
npm打包慢问题:
2.1 挂载缓存卷
-v /var/jenkins_home/.npm:/root/.npm
2.2 设置淘宝源
npm config set registry https://registry.npm.taobao.org
网站标题:在流水线中使用容器进行编译构建
网页网址:http://www.shufengxianlan.com/qtweb/news5/513255.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联