詹金斯(Jenkins)的飞行路线-无法解析位置

时间:2019-01-23 11:10:54

标签: jenkins flyway

我正在尝试通过在其中一个阶段中运行shell命令在ci / cd管道中将数据库迁移与Flyway集成在一起。 (因为不允许我向管道添加任何新插件,所以不能使用Flyway插件)

我已经尝试过:

    stage('migrate-sql') {
      steps {
        sh """
          docker run --rm \
          -v /GetShorty/Apis/Sql:/flyway/sql \
          boxfuse/flyway:5.2.4 \
          -url=jdbc:postgresql://****:5432/**** \
          -user=**** \
          -password=**** \
          -baselineOnMigrate=false \
          -locations=/GetShorty/Apis/Sql \
          -connectRetries=60 \
          migrate
        """
      }
    }

但由于似乎找不到迁移文件夹,因此未应用任何迁移

WARNING: Unable to resolve location /GetShorty/Apis/Sql

Successfully validated 0 migrations (execution time 00:00.378s)

Current version of schema "public": << Empty Schema >>

Schema "public" is up to date. No migration necessary.

考虑以下投影结构:

project structure

你知道这里可能出什么问题吗?

2 个答案:

答案 0 :(得分:2)

docker卷设置将主机上的/GetShorty/Apis/Sql目录安装到容器内的/flyway/sql目录:

-v /GetShorty/Apis/Sql:/flyway/sql

Flyway在容器内运行,因此locations标志必须是其中的目录:

-locations=/flyway/sql

答案 1 :(得分:0)

跌倒这个issue时,我意识到自己面临着类似的问题。

我设法解决该问题的方法是在名为flyway的根项目中创建一个单独的文件夹,其中包含一个sql文件夹,其中包含所有迁移以及以下Dockerfile

FROM boxfuse/flyway:5.2.4

COPY ./sql ./sql

回到jenkins文件,我添加了一个新步骤来构建docker映像:

  DOCKER_IMAGE_FLYWAY = "flyway"

  stages {
    stage('build docker images') {
      steps {
        script {
          dockerImage_flyway = docker.build("$DOCKER_REGISTRY/${DOCKER_PROJECT}/${DOCKER_IMAGE_FLYWAY}:${env.BUILD_NUMBER}", "flyway")
        }
      }
    }

并修改了迁移阶段以使用该图像

stage('migrate-sql') {
      steps {
        sh """
            docker run --rm \
            "$DOCKER_REGISTRY/${DOCKER_PROJECT}/${DOCKER_IMAGE_FLYWAY}:${env.BUILD_NUMBER}" \
            -url=jdbc:postgresql://****:5432/**** \
            -user=**** \
            -password=**** \
            -baselineOnMigrate=false \
            -schemas=**** \
            -connectRetries=60 \
            migrate
          """
      }
    }

现在就像魅力一样。