在openshift中使用jenkins时,如何确保在正确的目录中调用了maven?

时间:2018-11-06 11:06:34

标签: jenkins openshift jenkins-pipeline

我在openshift项目中运行着詹金斯短暂的吊舱。这是我的Jenkinsfile。

var withoutData: DictionaryLiteral = [String: [RealmObject]]()

我得到的错误是...

Cannot convert value of type '[String : [RealmObject]]' to specified type 'DictionaryLiteral'

我通过oc rsh jenkins-1-vwt2g进入了詹金斯豆荚

并尝试查找/ opt / app-root / src目录

var withData: DictionaryLiteral = ["test": [RealmObject()]]

我还寻找了hello-world-service-1.0.0.jar

pipeline{
    agent {
        label 'maven'
    }
    stages{
        stage('Checkout from GitLab'){
            steps{
                echo "GitLab Check out..."
                git branch: "<git-branch-here>",
                credentialsId: "<gitlab-credentials-here>",
                url: "git@gitlab.hostname.blah:projects/spring-boot-helloworld.git"
            }
        }
        stage('Invoking mvn commands'){
            steps{

                sh "mvn clean install package"
            }
        }
        stage('Create the Image Builder'){
            when{
                expression{
                    openshift.withCluster(){
                        return !openshift.selector("bc", "new-pipeline").exists()
                    }
                }
            }
            steps{
                script{
                    openshift.withCluster(){
                        openshift.withProject(){
                            echo "Creating a new build."
                            def created = openshift.newBuild("--name=new-pipeline", "--image-stream=springboot-maven3", "--binary")

                        }
                    }
                }
            }
        }

    }
}

但是我没有找到任何东西。

我在寻找git源的下载目录。

[start-build:buildconfig/new-pipeline] [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/opt/app-root/src). Please verify you invoked Maven from the correct directory. -> [Help 1]
[start-build:buildconfig/new-pipeline] [ERROR]
[start-build:buildconfig/new-pipeline] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[start-build:buildconfig/new-pipeline] [ERROR] Re-run Maven using the -X switch to enable full debug logging.
[start-build:buildconfig/new-pipeline] [ERROR]
[start-build:buildconfig/new-pipeline] [ERROR] For more information about the errors and possible solutions, please read the following articles:
[start-build:buildconfig/new-pipeline] [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException
[start-build:buildconfig/new-pipeline] error: build error: non-zero (13) exit code from codecentric/springboot-maven3-centos@sha256:91ecee201c42cfde8616dfe7b5c77c4f6100f95f50c6e8ffe16a78c99dde59bf
[start-build:buildconfig/new-pipeline] 
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Create DEV)
Stage 'Create DEV' skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: Error running start-build on at least one item: [buildconfig/new-pipeline];
{reference={}, err=Uploading file "target/hello-world-service-1.0.0.jar" as binary input for the build ...
error: the build pipelineproject/new-pipeline-1 status is "Failed", verb=start-build, cmd=oc --server=https://172.30.0.1:443 --certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt --namespace=pipelineproject --token=XXXXX start-build buildconfig/new-pipeline --from-file=./target/hello-world-service-1.0.0.jar --wait --follow -o=name , out=build/new-pipeline-1
Receiving source from STDIN as file hello-world-service-1.0.0.jar
---> Restore build artifacts
---> Installing application source
---> Building Spring Boot application from source
--> # MVN_ARGS =
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.095 s
[INFO] Finished at: 2018-11-06T04:19:02+00:00
[INFO] Final Memory: 13M/360M
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/opt/app-root/src). Please verify you invoked Maven from the correct directory. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException
error: build error: non-zero (13) exit code from codecentric/springboot-maven3-centos@sha256:91ecee201c42cfde8616dfe7b5c77c4f6100f95f50c6e8ffe16a78c99dde59bf, status=1}

错误消息提到了/ opt / app-root / src,但是git源被下载到的源文件夹是/ var / lib / jenkins / jobs / pipelineproject / jobs / pipelineproject-hello-world-pipeline-ver2 / workspace

我该如何在openshift的jenkins管道中对此进行协调,因此当我执行startBuild时,它知道实际的jar文件在哪里(我什至不知道maven在哪里生成了jar文件-在执行mvn clean install package命令之后)。

顺便说一句,在mvn命令中,特别是install命令,这是相关的日志

sh-4.2$ pwd
/opt
sh-4.2$ cd app-root
sh: cd: app-root: No such file or directory

我有一个/ home目录,但不包含任何内容(即没有jenkins / ...目录)。

sh-4.2$ cd /
sh-4.2$ find . -name hello*.jar

1 个答案:

答案 0 :(得分:0)

我能够通过使用其他图像流来完成这项工作(即,我用redhat openjdk图像替换了springboot-maven3图像)。同时,在jenkins容器内找不到我要查找的不同目录,而是默认在Jenkins容器提供的Maven从属容器中。