1

I'm working on developing a build pipeline for LabVIEW projects and have reached the point where I can build a LabVIEW project from a batch file or windows cmd. The process is pretty simple. I'm calling some LabVIEW code from the LabVIEW engine that will build the project. The process works from within a batch script but the second I put the contents of the batch file into the jenkins build step it fails with the message.

'--' is not recognized as an internal or external command,
operable program or batch file.

The contents of the batch script are as follows:

@echo off
%LabVIEW17% %pBUILD% -- "<path to my project>.lvproj"

Where %LabVIEW17% is the path to the LabVIEW.exe and %pBUILD% is the path to the LabVIEW code that builds projects. The format is based on some information I found here: http://www.ni.com/example/30051/en/

Why would '--' fail from Jenkins and not from cmd or a batch file? What is the purpose of the -- input?

Jake
  • 43
  • 1
  • 10
  • 2
    That is explained pretty simple. In the environment the batch file is running there is no environment variable `LabVIEW17` and also no environment variable pBUILD and for that reason the first non-whitespace separated argument string is `--` which of course is not the file name of an executable or script to execute. Perhaps you have defined the two environment variables for your user account, but Jenkins is running with a different user account. – Mofi Jul 03 '18 at 17:21
  • Just for clarification, I set both of these variables in the system environment variables on the machine that jenkins is running on. – Jake Jul 03 '18 at 17:29
  • 1
    And you have restarted the entire machine or at least Jenkins after making the modification in Windows system settings? Please take a look on [What is the reason for '...' is not recognized as an internal or external command, operable program or batch file?](https://stackoverflow.com/a/41461002/3074564) – Mofi Jul 03 '18 at 17:31
  • Ok, I feel dumb now. But between restarting the machine and the setx command my problem is now fixed. It makes a lot of sense that I would have to restart the machine as Jenkins is running as a service. That perfectly explains why both cmd and the batch file would work because they both receive environment variable updates upon opening, whereas jenkins would have been continuously running in the background. Thanks a ton for your help. – Jake Jul 03 '18 at 17:45
  • 1
    `SETX` only takes affect on any new environments started after `SETX` has executed. Any existing environments do not have access to the new variables created by `SETX`. – Squashman Jul 03 '18 at 18:19
  • Good to know, does `SETX` persist over power cycles? – Jake Jul 03 '18 at 19:59
  • As answer on [What is the reason for '…' is not recognized as an internal or external command, operable program or batch file?](https://stackoverflow.com/a/41461002/3074564) explains in detail, the command `setx` saves the environment variable and its value persistent in Windows registry for current user or all users depending on option `/M` (Machine) __and__ sends the `WM_SETTINGCHANGE` message to all top-level windows to inform the running applications about changed system parameters. – Mofi Jul 04 '18 at 05:58
  • Windows Explorer (all running instances including desktop instance) as well as some applications like Total Commander process this message and update their __local__ environment variables accordingly. But as written also in the answer, most processes already running ignore that message or don't get even activated on this message and so do not update their __local__ list of environment variables. So for Jenkins running as service it is best to restart Windows to get the update on __user__ or __system__ environment variables applied to __local__ list of environment variables of Jenkins service. – Mofi Jul 04 '18 at 05:59

1 Answers1

1

Most probably your %LabVIEW17% and %pBUILD% are empty and your line is interpreted like:

-- "<path to my project>.lvproj"

try to set the variable on machine level but not only for the user.

If your jenkins is installed as a service it executes the scripts as administrator/system and environment variables set on user level will be not taken into account. To set the variables on machine level check setx command.

npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • Jenkins is currently installed as a service so I tried the setx command. Following the help for the setx command I ran setx LABVIEW17 %LABVIEW17%. If I understand what this is doing this should take my environment variable and is writing it to the master environment in the registry. Same for the pBUILD variable. Still seeing the same error on the Jenkins side. – Jake Jul 03 '18 at 17:39