Jenkins不会运行更新的Jenkinsfile

时间:2019-08-13 13:43:58

标签: jenkins jenkins-pipeline

我在Docker容器中运行Jenkins和GitLab。 Jenkins Maven Pipeline从GitLab实例获取其代码。管道中的commit标签是最后一次正确的推送,但是管道始终使用初始的Jenkinsfile,并且每次推送后都不会更新。

pipeline {
    enviroment{
      BUILD_IMAGE = getImageName()
      REGISTRY = 'http://127.0.0.1:8082'
      CRED_ID = 'max'
    }
    def app

    def getImageName(){
        return mvn help:evaluate -Dexpression=project.build.finalName -q -DforceStdout
    }

    agent any

    stages {
        stage('build') {
            steps {
                sh 'mvn package -Dmaven.test.skip=true'
            }
        }
        stage('test'){
            steps {
                sh 'mvn test'
            }
        }
        stage('docker build'){
            steps{
                app = docker.build(BUILD_IMAGE)
            }
        }
        stage("docker push"){
            steps{
                docker.withRegistry(REGISTRY,CRED_ID){
                    GIT_TAG = sh(git rev-parse --short HEAD)
                    app.push(GIT_TAG)
                    app.push("latest")
                }
            }
        }
    }
}

这里是docker-compose

version: '3.7'

services:
  gitlab:
    image: gitlab/gitlab-ce
    ports: 
      - "9080:80"
      - "9443:433"
      - "9022:22"
    volumes:
      - ./data/gitlab/config:/etc/gitlab
      - ./data/gitlab/logs:/var/log/gitlab
      - ./data/gitlab/data:/var/opt/gitlab

  jenkins:
    build:
      context: ./jenkins/.
    ports:
      - "9083:8080"
    depends_on:
      - gitlab
      - nexus
    volumes:
      - ./data/jenkins:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/local/Cellar/maven/3.6.1/libexec:/usr/local/Cellar/maven/3.6.1/libexec
    links:
      - gitlab:gitlab
      - nexus:nexus
    depends_on:
      - gitlab

和相应的Dockerfile

FROM jenkins/jenkins

USER root
RUN apt-get update -qq \
    && apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common 
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/debian \
    $(lsb_release -cs) \
    stable"
RUN apt-get update  -qq \
    && apt-get install docker-ce -y
RUN usermod -aG docker jenkins

浏览(Jenkins容器的)共享卷,发现存储库。它具有新的Jenkinsfile。

也许Jenkins会缓存最初的Jenkins文件,而忽略更新的文件?

0 个答案:

没有答案