2023-06-26

why jenkins showing git maven not found error even git and maven installed?

`hi there,hope you are doing well. I am new to Jenkins, and errors are encountered during practice. i took a sample project. error and jenkins file content posted below please have a look into it. feel free to ask if you have any questions. please suggest solution.

Thank you for your support and help.`

Error as below

Started by user admin
Obtained Jenkins-decnew from git https://github.com/kdhani/myweb-p1.git
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/pipeline1
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
**Selected Git installation does not exist. Using Default
**The recommended git tool is: NONE
using credential gitid
 > /usr/bin/git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/pipeline1/.git # timeout=10
Fetching changes from the remote Git repository
 > /usr/bin/git config remote.origin.url https://github.com/kdhani/myweb-p1.git # timeout=10
Fetching upstream changes from https://github.com/kdhani/myweb-p1.git
 > /usr/bin/git --version # timeout=10
 > git --version # 'git version 2.40.1'
using GIT_ASKPASS to set credentials 
 > /usr/bin/git fetch --tags --force --progress -- https://github.com/kdhani/myweb-p1.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > /usr/bin/git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision c8f4db412eaf023b2ae78c1a9e168db17ea6ac73 (refs/remotes/origin/master)
 > /usr/bin/git config core.sparsecheckout # timeout=10
 > /usr/bin/git checkout -f c8f4db412eaf023b2ae78c1a9e168db17ea6ac73 # timeout=10
Commit message: "Update Jenkins-decnew"
 > /usr/bin/git rev-list --no-walk c8f4db412eaf023b2ae78c1a9e168db17ea6ac73 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Git Checkout)
[Pipeline] git
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE
using credential gitid
 > /usr/bin/git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/pipeline1/.git # timeout=10
Fetching changes from the remote Git repository
 > /usr/bin/git config remote.origin.url https://github.com/kdhani/myweb-p1.git # timeout=10
Fetching upstream changes from https://github.com/kdhani/myweb-p1.git
 > /usr/bin/git --version # timeout=10
 > git --version # 'git version 2.40.1'
using GIT_ASKPASS to set credentials 
 > /usr/bin/git fetch --tags --force --progress -- https://github.com/kdhani/myweb-p1.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > /usr/bin/git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision c8f4db412eaf023b2ae78c1a9e168db17ea6ac73 (refs/remotes/origin/master)
 > /usr/bin/git config core.sparsecheckout # timeout=10
 > /usr/bin/git checkout -f c8f4db412eaf023b2ae78c1a9e168db17ea6ac73 # timeout=10
 > /usr/bin/git branch -a -v --no-abbrev # timeout=10
 > /usr/bin/git branch -D master # timeout=10
 > /usr/bin/git checkout -b master c8f4db412eaf023b2ae78c1a9e168db17ea6ac73 # timeout=10
Commit message: "Update Jenkins-decnew"
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Maven Build)
[Pipeline] sh
**+ mvn clean package
**/var/lib/jenkins/workspace/pipeline1@tmp/durable-7e042d4d/script.sh: line 1: **mvn: command not found**
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (deploy-dev)
Stage "deploy-dev" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
REST API
Jenkins 2.401.1

jenkins file content from here :)

pipeline{

    agent any
    
    environment{
        PATH = "/opt/maven3/bin:$PATH"
    }
    stages{
        stage("Git Checkout"){
            steps{
                git credentialsId: 'gitid', url: 'https://github.com/kdhani/myweb-p1.git'
            }
        }
        stage("Maven Build"){
            steps{
                sh "mvn clean package"
                sh "mv target/*.war target/myweb.war"
            }
        }
        stage("deploy-dev"){
            steps{
                sshagent(['tomcat-new']) {
                    
                sh """
                    scp -o StrictHostKeyChecking=no target/myweb.war  ec2-user@172.31.33.108:/home/ec2-user/apache-tomcat-9.0.63/webapps/
                    
                    ssh ec2-user@172.31.33.108 /home/ec2-user/apache-tomcat-9.0.63/bin/shutdown.sh
                    
                    ssh ec2-user@172.31.33.108 /home/ec2-user/apache-tomcat-9.0.63/bin/startup.sh
                
                """
            }
            
            }
        }
    }
}



No comments:

Post a Comment