Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Jenkins CI和外部jar构建Maven项目,而不是集成在pom.xml中_Maven_Jenkins_Jar_Continuous Integration - Fatal编程技术网

通过Jenkins CI和外部jar构建Maven项目,而不是集成在pom.xml中

通过Jenkins CI和外部jar构建Maven项目,而不是集成在pom.xml中,maven,jenkins,jar,continuous-integration,Maven,Jenkins,Jar,Continuous Integration,我从bitbucket那里得到了一个遗留项目,在Docker容器上与Jenkins连接。构建失败,因为外部jar只能通过链接使用 我试图通过Jenkins文件中的curl下载jar,并为其创建了自己的my-jar-pom.xml: pipeline { agent {docker {image: 'maven: 3.6.3'} } tools { jdk "jdk-1.8" } stages { stage('myStage'

我从bitbucket那里得到了一个遗留项目,在Docker容器上与Jenkins连接。构建失败,因为外部jar只能通过链接使用

我试图通过Jenkins文件中的curl下载jar,并为其创建了自己的my-jar-pom.xml:

pipeline {

    agent {docker {image: 'maven: 3.6.3'} }

    tools {
        jdk "jdk-1.8"
    }

    stages {
        stage('myStage') {
            steps {
                step('Get Library') {
                    >&2 echo 'Get Library'
                    sh 'curl -O link-to-my-jar.jar'
                }
                step('Create POM') {
                    sh 'echo "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n
                                 <groupId>my-group-id</groupId>\n
                                 <artifactId>my-artifact-id</artifactId>\n
                                 <version>1.0</version>\n
                             </project>" > my-jar.pom'
                    >&2 echo 'create POM'
                }
                step('Install POM') {
                    mvn install:install-file -Dfile=my-jar.jar -DpomFile=my-jar.pom
                    >&2 echo 'install POM'
                }
                step('Install') {
                    sh 'mvn -B clean install'
                    >&2 echo 'install mvn'
                }
            }
        }
    }
}

你的方法很好。它应该会起作用


但是您不需要自己创建POM。您可以让
install:install file
创建它。只需在缺少的地方添加以下内容: 1) 在my Jenkins的工具部分安装JDK 2) 在“工具”部分安装Maven

然后我将代理更改为
agent any
,并将maven添加到工具中:

agent any

tools {
    jdk "JDK-8"
    maven "Maven-3.6.3"
}
-DgeneratePom=true没有真正起作用,可能是我的错,但我发现这是一个可行的解决方案:

stages {
    stage('AXSUTILS') {
        steps {
            script {
                echo 'Get Library'
                sh 'curl -O http://link.to.my.jar/my-jar/1.0/my-jar.jar'

                echo 'create POM'
                sh 'echo "<project xmlns=\\"http://maven.apache.org/POM/4.0.0\\" xmlns:xsi=\\"http://www.w3.org/2001/XMLSchema-instance\\" xsi:schemaLocation=\\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xs\\"> <groupId>com.xx.xml</groupId> <artifactId>my-artifact</artifactId> <version>1.0</version> </project>" > my-jar.pom'

                echo 'install POM'
                sh 'mvn install:install-file -Dfile=my-jar.jar -DpomFile=my-jar.pom'

                echo 'install mvn'
                sh 'mvn -B -U -X clean install'
            }
        }
    }
}
阶段{
阶段(‘AXSUTILS’){
台阶{
剧本{
echo“获取库”
sh'curl-Ohttp://link.to.my.jar/my-jar/1.0/my-jar.jar'
echo“创建POM”
sh'echo“com.xx.xml我的工件1.0”>my jar.pom'
echo“安装POM”
sh'mvn install:install file-Dfile=my-jar.jar-DpomFile=my-jar.pom'
echo“安装mvn”
sh“mvn-B-U-X清洁安装”
}
}
}
}

还要注意遗漏的引语,我花了很长时间才意识到詹金斯删除了“所以你需要”这样的引语“左。

感谢您的输入,不幸的是它仍然无法工作。我查看了Jenkins构建的控制台输出,但没有任何提示。知道吗?输出显示Jenkins无法下载jar。这可能有几个原因:首先,可能是缓存问题:尝试使用
-U
构建。其次,您可能有错误的存储库地址,或者工件不在该存储库中。第三,这里可能存在网络/代理/防火墙问题(通常是这样),我发现我将我的作业配置为一个Maven项目,它似乎忽略了Jenkins文件。在将第二个作业创建为多分支管道后,控制台输出((install-file)-DgeneratePom)是一个二进制表达式,但在install-file-DgeneratePom=true处它应该是一个变量表达式。下载应该可以工作,正如我在控制台中尝试的那样。
stages {
    stage('AXSUTILS') {
        steps {
            script {
                echo 'Get Library'
                sh 'curl -O http://link.to.my.jar/my-jar/1.0/my-jar.jar'

                echo 'create POM'
                sh 'echo "<project xmlns=\\"http://maven.apache.org/POM/4.0.0\\" xmlns:xsi=\\"http://www.w3.org/2001/XMLSchema-instance\\" xsi:schemaLocation=\\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xs\\"> <groupId>com.xx.xml</groupId> <artifactId>my-artifact</artifactId> <version>1.0</version> </project>" > my-jar.pom'

                echo 'install POM'
                sh 'mvn install:install-file -Dfile=my-jar.jar -DpomFile=my-jar.pom'

                echo 'install mvn'
                sh 'mvn -B -U -X clean install'
            }
        }
    }
}