Jenkins打包流水线项目是报错:script.sh:行1: mvn: 未找到命令解决方案-实战版

前一篇:k8s(kubernetes)通过yaml从harbor拉取镜像(史诗级,保姆级)https://blog.csdn.net/fsjwin/article/details/109911495
在这里插入图片描述

pipeline {
    agent any

    stages {
        stage('1. pull') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'gitlab-suhua', url: 'http://git.icentown.com/wuye/wy-user.git']]])
            }
        }
        
         stage('2. image') {
            steps {
                sh label: '', script: 'mvn clean package -Dmaven.test.skip=true'
            }
        }
        
         stage('3. finish') {
            steps {
                echo 'finish'
            }
        }
    }
}

部分错误日志:

+ mvn clean package -Dmaven.test.skip=true
/data/jenkins/workspace/yuhl_pipeline@tmp/durable-0486c9c4/script.sh:行1: mvn: 未找到命令
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (3. finish)

完整的错误日志:

Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /data/jenkins/workspace/yuhl_pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (1. pull)
[Pipeline] checkout
The recommended git tool is: NONE
using credential gitlab-suhua
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url http://git.icentown.com/wuye/wy-user.git # timeout=10
Fetching upstream changes from http://git.icentown.com/wuye/wy-user.git
 > git --version # timeout=10
 > git --version # 'git version 1.8.3.1'
using GIT_ASKPASS to set credentials gitlab账户密码
 > git fetch --tags --progress http://git.icentown.com/wuye/wy-user.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision 810be276dd9447a84a6157524d97561ba4eaf3c3 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 810be276dd9447a84a6157524d97561ba4eaf3c3 # timeout=10
Commit message: "去掉微信解密无关的参数;"
 > git rev-list --no-walk 810be276dd9447a84a6157524d97561ba4eaf3c3 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (2. image)
[Pipeline] sh
+ mvn clean package -Dmaven.test.skip=true
/data/jenkins/workspace/yuhl_pipeline@tmp/durable-0486c9c4/script.sh:行1: mvn: 未找到命令
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (3. finish)
Stage "3. finish" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE

下面解决方案:

1. 查看环境变量,无问题:

[root@dev-wuye-docker01 ~]# echo $PATH
/data/gradle/bin:/data/node/bin:/data/apache-maven-3.6.3/bin:/usr/local/jdk1.8.0_221/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

在这里插入图片描述

2.配置系统中设置 Environment variables环境变量

在这里插入图片描述

在这里插入图片描述

3.网上说还要安装Maven Integration plugin

因为我提前已经安装过了,所有这点没有发言权,如果小伙伴们遇到了。不妨安装一下。
在这里插入图片描述

4. 重新构建成功

在这里插入图片描述

成功日志如下:


SuccessConsole Output
Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /data/jenkins/workspace/yuhl_pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (1. pull)
[Pipeline] checkout
The recommended git tool is: NONE
using credential gitlab-suhua
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url http://git.icentown.com/wuye/wy-user.git # timeout=10
Fetching upstream changes from http://git.icentown.com/wuye/wy-user.git
 > git --version # timeout=10
 > git --version # 'git version 1.8.3.1'
using GIT_ASKPASS to set credentials gitlab账户密码
 > git fetch --tags --progress http://git.icentown.com/wuye/wy-user.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision 810be276dd9447a84a6157524d97561ba4eaf3c3 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 810be276dd9447a84a6157524d97561ba4eaf3c3 # timeout=10
Commit message: "去掉微信解密无关的参数;"
 > git rev-list --no-walk 810be276dd9447a84a6157524d97561ba4eaf3c3 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (2. image)
[Pipeline] sh
+ mvn clean package -Dmaven.test.skip=true
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for org.springblade:blade-common:jar:2.5.1.RELEASE
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ com.centown:wy-user:2.5.1.RELEASE, /data/jenkins/workspace/yuhl_pipeline/pom.xml, line 150, column 21
[WARNING] 'build.plugins.plugin.version' for com.spotify:dockerfile-maven-plugin is missing. @ com.centown:wy-user:2.5.1.RELEASE, /data/jenkins/workspace/yuhl_pipeline/pom.xml, line 139, column 21
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.centown:user:jar:2.5.1.RELEASE
[WARNING] 'version' contains an expression but should be a constant. @ com.centown:user:${bladex.project.version}, /data/jenkins/workspace/yuhl_pipeline/blade-service/user/pom.xml, line 16, column 14
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ com.centown:wy-user:2.5.1.RELEASE, /data/jenkins/workspace/yuhl_pipeline/pom.xml, line 150, column 21
[WARNING] 'build.plugins.plugin.version' for com.spotify:dockerfile-maven-plugin is missing. @ com.centown:wy-user:2.5.1.RELEASE, /data/jenkins/workspace/yuhl_pipeline/pom.xml, line 139, column 21
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.centown:blade-service:pom:2.5.0.RELEASE
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ com.centown:wy-user:2.5.1.RELEASE, /data/jenkins/workspace/yuhl_pipeline/pom.xml, line 150, column 21
[WARNING] 'build.plugins.plugin.version' for com.spotify:dockerfile-maven-plugin is missing. @ com.centown:wy-user:2.5.1.RELEASE, /data/jenkins/workspace/yuhl_pipeline/pom.xml, line 139, column 21
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.centown:user-api:jar:2.5.1.RELEASE
[WARNING] 'version' contains an expression but should be a constant. @ com.centown:user-api:${bladex.project.version}, /data/jenkins/workspace/yuhl_pipeline/blade-service-api/user-api/pom.xml, line 14, column 14
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ com.centown:wy-user:2.5.1.RELEASE, /data/jenkins/workspace/yuhl_pipeline/pom.xml, line 150, column 21
[WARNING] 'build.plugins.plugin.version' for com.spotify:dockerfile-maven-plugin is missing. @ com.centown:wy-user:2.5.1.RELEASE, /data/jenkins/workspace/yuhl_pipeline/pom.xml, line 139, column 21
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.centown:blade-service-api:pom:2.5.0.RELEASE
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ com.centown:wy-user:2.5.1.RELEASE, /data/jenkins/workspace/yuhl_pipeline/pom.xml, line 150, column 21
[WARNING] 'build.plugins.plugin.version' for com.spotify:dockerfile-maven-plugin is missing. @ com.centown:wy-user:2.5.1.RELEASE, /data/jenkins/workspace/yuhl_pipeline/pom.xml, line 139, column 21
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.centown:wy-user:pom:2.5.1.RELEASE
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 150, column 21
[WARNING] 'build.plugins.plugin.version' for com.spotify:dockerfile-maven-plugin is missing. @ line 139, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] wy-user                                                            [pom]
[INFO] blade-common                                                       [jar]
[INFO] blade-service-api                                                  [pom]
[INFO] user-api                                                           [jar]
[INFO] blade-service                                                      [pom]
[INFO] user                                                               [jar]
[INFO] 
[INFO] ------------------------< com.centown:wy-user >-------------------------
[INFO] Building wy-user 2.5.1.RELEASE                                     [1/6]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ wy-user ---
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.1.13.RELEASE:repackage (default) @ wy-user ---
[INFO] 
[INFO] --------------------< org.springblade:blade-common >--------------------
[INFO] Building blade-common 2.5.1.RELEASE                                [2/6]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ blade-common ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ blade-common ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ blade-common ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to /data/jenkins/workspace/yuhl_pipeline/blade-common/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ blade-common ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ blade-common ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ blade-common ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ blade-common ---
[INFO] Building jar: /data/jenkins/workspace/yuhl_pipeline/blade-common/target/blade-common.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.1.13.RELEASE:repackage (default) @ blade-common ---
[INFO] 
[INFO] -------------------< com.centown:blade-service-api >--------------------
[INFO] Building blade-service-api 2.5.0.RELEASE                           [3/6]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ blade-service-api ---
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.1.13.RELEASE:repackage (default) @ blade-service-api ---
[INFO] 
[INFO] ------------------------< com.centown:user-api >------------------------
[INFO] Building user-api 2.5.1.RELEASE                                    [4/6]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ user-api ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ user-api ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /data/jenkins/workspace/yuhl_pipeline/blade-service-api/user-api/src/main/resources
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ user-api ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to /data/jenkins/workspace/yuhl_pipeline/blade-service-api/user-api/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ user-api ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ user-api ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ user-api ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ user-api ---
[INFO] Building jar: /data/jenkins/workspace/yuhl_pipeline/blade-service-api/user-api/target/user-api.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.1.13.RELEASE:repackage (default) @ user-api ---
[INFO] 
[INFO] ---------------------< com.centown:blade-service >----------------------
[INFO] Building blade-service 2.5.0.RELEASE                               [5/6]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ blade-service ---
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.1.13.RELEASE:repackage (default) @ blade-service ---
[INFO] 
[INFO] --------------------------< com.centown:user >--------------------------
[INFO] Building user 2.5.1.RELEASE                                        [6/6]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ user ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ user ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] Copying 4 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ user ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 42 source files to /data/jenkins/workspace/yuhl_pipeline/blade-service/user/target/classes
[WARNING] /data/jenkins/workspace/yuhl_pipeline/blade-service/user/src/main/java/com/centown/user/service/impl/WyWxUserServiceImpl.java: /data/jenkins/workspace/yuhl_pipeline/blade-service/user/src/main/java/com/centown/user/service/impl/WyWxUserServiceImpl.java使用了未经检查或不安全的操作。
[WARNING] /data/jenkins/workspace/yuhl_pipeline/blade-service/user/src/main/java/com/centown/user/service/impl/WyWxUserServiceImpl.java: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ user ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ user ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ user ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ user ---
[INFO] Building jar: /data/jenkins/workspace/yuhl_pipeline/blade-service/user/target/user.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.1.13.RELEASE:repackage (default) @ user ---
[INFO] Replacing main artifact with repackaged archive
[INFO] 
[INFO] --- maven-antrun-plugin:1.3:run (default) @ user ---
[INFO] Executing tasks
     [copy] Copying 1 file to /data/jenkins/workspace/yuhl_pipeline/target
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] wy-user 2.5.1.RELEASE .............................. SUCCESS [  1.123 s]
[INFO] blade-common 2.5.1.RELEASE ......................... SUCCESS [  2.678 s]
[INFO] blade-service-api 2.5.0.RELEASE .................... SUCCESS [  0.357 s]
[INFO] user-api 2.5.1.RELEASE ............................. SUCCESS [  1.266 s]
[INFO] blade-service 2.5.0.RELEASE ........................ SUCCESS [  0.046 s]
[INFO] user 2.5.1.RELEASE ................................. SUCCESS [  3.810 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  9.978 s
[INFO] Finished at: 2020-11-22T16:54:18+08:00
[INFO] ------------------------------------------------------------------------
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (3. finish)
[Pipeline] echo
finish
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

下一篇:k8s(kubernetes)通过jenkins从harbor拉取镜像,包括yaml传参(史诗级,保姆级) https://blog.csdn.net/fsjwin/article/details/110004762

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值