0

I'm attempting to get Jenkins to run a .bat file which contains a call to Poetry (for package management).

However, when running this .bat file via Jenkins, I'm getting a "'poetry' is not recognized as an internal or external command, operable program or batch file." error.

I believe this is due to the .bat file failing when it attempts to run a "call poetry check" command.

The .bat file runs successfully when run manually.

Is there some obvious feature of Jenkins that I'm missing here?

I'm aware that there is an alternative method of embedding poetry into Jenkins with direct commands. However this project is about to be passed on to someone else, and they would not be able to maintain that.

I've reproduced the key code below (the Jenkins code calling the .bat file, the code in the .bat file and the error output from Jenkins).

Jenkins code (standard pipeline with default settings):

pipeline {
    agent any

    stages {
        stage('Main') {
            steps {
                bat 'E:\\project-folder\\project_run.bat'
            }
        }
    }
}

Bat file code:

@echo off

cd /d "E:\project-folder\"


call poetry check && (
echo poetry checked
) || (
echo Problem with poetry
EXIT /B
)

echo Installing prod packages
call poetry install --no-dev && (
echo Production packages successfully installed
) || (
echo Problem installing packages to environment
EXIT /B
)

call python local-program.py
EXIT /B
)

Jenkins Error:

C:\Windows\system32\config\systemprofile\AppData\Local\Jenkins.jenkins\workspace[Pipeline_Name]>E:\project-folder\project_run.bat Moving to project directory 'poetry' is not recognized as an internal or external command, operable program or batch file. Problem with poetry

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • Where is `poetry` located? `call poetry […]` looks it up in the current working directory, which is set to `E:\project-folder`. Is it there? Or is its parent path specified in the `PATH` variable? – aschipfl Feb 04 '22 at 18:37

1 Answers1

0

Windows is looking up executables on the path you specify. If you run a command without a path, Windows looks for the command/executable in all directories specified in the environment variable PATH.

Very likely your Jenkins is running with different path settings than your interactive shell.

What you can do:

  • specify the full path to the command you want to raise in Jenkins
  • set the PATH variable in the Jenkins job prior to running the command
  • set the PATH variable before invoking Jenkins

Apart from the directory, Windows also has to check extensions. If you run poetry, Windows may have to find poetry.com, poetry.exe, poetry.bat or poetry.cmd. I suspect one of these files reside in E:\project-folder. To understand which files Windows checks for and the preference, have a look at the environment variable PATHEXT.

So to better understand these differences you can run the command set without parameters. Do that on the command line, and add the same command into your Jenkins job.

Queeg
  • 7,748
  • 1
  • 16
  • 42