'Docker-compose error in Jenkins "docker-compose: No such file or directory"

I am making a CI/CD pipeline for an application with React Js front-end and Java Spring Boot backend. When I run the build every time fail and get an error. I face this error with both Jenkins running on the server and running on my local machine.

Error Jenkins running on local :+ /usr/bin/docker-compose up --build -d
/var/root/.jenkins/workspace/flight-test-pipeline@tmp/durable-3512619f/script.sh: line 1: /usr/bin/docker-compose: No such file or directory


Error Jenkins running on server:  + docker-compose build
/var/lib/jenkins/workspace/Build-pipeline@tmp/durable-94a5213e/script.sh: 1: /var/lib/jenkins/workspace/Build-pipeline@tmp/durable-94a5213e/script.sh: docker-compose: not found

Jenkins script is here:

pipeline {
  environment {
        PATH = "$PATH:/usr/local/bin/docker-compose"
    }
    agent any
  stages {  
    stage('Start container') {
      steps {
        sh "/usr/bin/docker-compose up --build -d"
      }
    }
    
    stage('Build') {

      steps {

        sh 'Docker build -t registry.has.de/jenk1:v1 .'

      }

    }
    stage('Login') {

      steps {

        sh 'echo docker login registry.has.de --username=furqan.iqbal --password=123...

      }

    }

    stage('Push to Has registry') {

      steps {

        sh '''
          Docker push registry.has.de/jenk1:v1
        '''

      }

    }

  }

}


Solution 1:[1]

If i recall correctly, Jenkins can't understand what '$PATH' is, so you need to do the following:

environment {
        p = sh 'echo $PATH'
        PATH = p + ':/usr/local/bin/docker-compose'
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1