导语:jenkins使用node镜像 构建前端服务。
今天发现以前的前端job编译报错了。提示node版本太低,打算用docker来做基础环境进行构建。以后升级版本也方便
流水线编译处修改为如下所示 .npm是缓存地址
stage('WebBuild') {
steps {
script {
docker.image('node:12.22.12').inside('-u 0:0 -v /root/.npm:/root/.npm') {
sh """
id
hostname
ip a
cd ${WORKSPACE}
npm config set unsafe-perm=true
npm config set cache /root/.npm
npm i --registry http://172.16.41.100:4873/
npm run build
"""
}
}
}
}
构建成功
中途提示does not seem to be running inside a container 似乎没有影响
如图显示的确是在容器中
加上docker构建
stage('WebBuild') {
steps {
script {
docker.image('node:12.22.12').inside('-u 0:0 -v /root/.npm:/root/.npm') {
sh """
id
hostname
ip a
cd ${WORKSPACE}
npm config set unsafe-perm=true
npm config set cache /root/.npm
npm i --registry http://172.16.41.100:4873/
npm run build
ls
"""
}
}
}
}
stage('deploy') {
// agent {
// label "10.10.3.245"
// }
steps {
script {
sh """
ls
cd ${WORKSPACE}
echo base image name: ${DOCKER_IMAGE}
echo image name: harbor.deepwise.com/dev/${JOB_NAME}:${Tag}
echo FROM harbor.deepwise.com/${DOCKER_IMAGE} > Dockerfile
echo RUN rm -rf /root/aiviewer >> Dockerfile
echo COPY dist /root/aiviewer >> Dockerfile
cat Dockerfile
docker build -t harbor.deepwise.com/dev/${JOB_NAME}:${Tag} --no-cache .
docker push harbor.deepwise.com/dev/${JOB_NAME}:${Tag}
###ssh root@172.16.10.107 -o "StrictHostKeyChecking no" "kubectl set image deployment/aiviewer aiviewer=harbor.deepwise.com/dev/${JOB_NAME}:${Tag} -n yitu"
"""
}
}
}