Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

batch file - Jenkins - cmd is not recognized

Environment:

  • Master Linux Jenkins server
  • Two Windows slave nodes
  • The windows slaves are running as a service

First Test

  • I create a Pipeline and use a use a "Execute Windows batch command" in the build section
  • In the Command box I put "C:Jenkinsmytest.bat"
  • I checked the box "Restrict where this project can be run" and write down the name of the Windows slave
  • I built the pipeline and was successful

Second Test

  • I create a Declarative Pipeline as follows:

    pipeline {  
        agent { label 'SiebelWindows' }
    
        stages {
            stage('Test Bat') {
               steps { 
                            bat 'C:\Jenkins\mytest.bat'
                            //bat 'start cmd.exe /c C:\Jenkins\mytest.bat'
                            //call C:\Jenkins\mytest.bat
                            }
                    }
        }
       }
    
  • In this case the build FAIL with error "cmd is not recognized as a internal o external command"

So, why can I run the .bat with a non-declarative pipeline, but fails with a declarative pipeline?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When I display the "Path" and the "PATH" variables, this was the result

Original_Path

The solution was redefine the PATH enviorement variable, like this

environment {

    PATH = "C:\WINDOWS\SYSTEM32"

}

@JustAProgrammer aske me if C:WINDOWSSYSTEM32 was in the PATH of my Windows machine, and that is correct, but seems like Jenkins master do not know the slave's Windows Path.

I resolve my issue, but I still looking for a complete solution, I need to set the PATH enviorement variable with ALL the path, no only C:WINDOWSSYSTEM32


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...