TFS Build Server doesn't pick up environment variables? - tfs

I've been trying to use heat to generate .wxs for a WiX install project with pre-build event command line.
Everything works fine locally but despite installing WiX on the build machine, configuring environment variables, restarting the build machine etc nothing seems to recognise variables when I run a build on TFS.
For example:
"$(WIX)bin\heat.exe" dir $(SolutionDir)MyProject\$(OutDir) -cg MyClient -gg -scom -sreg -sfrag -srd -dr CLIENTFOLDER -var var.ClientSourceDir -out "$(ProjectDir)Client.wxs"
outputs
"bin\heat.exe" dir CORRECT_PATH -cg MyClient -gg -scom -sreg -sfrag -srd -dr CLIENTFOLDER -var var.ClientSourceDir -out "CORRECT_PATH"" exited with code 3
If I do echo $(WIX) it just outputs echo, whereas running it locally it outputs the WiX directory which seems to suggest it picks up no environment variables.
If I log on to the build machine and use the command line on it these variables are fine.

Related

TFS linux agent ignores Build.Repository.Clean variable

Situation:
TFS 2018
build process consists of two phases -- executed on Windows and Linux agents respectively
Get sources (TFVC) has Clean flag set to false
Problem:
Linux agent (unlike it's counterpart) ignores Clean flag -- it always executes tf workspace -delete, ... -new, etc.
I've added "print variables" step and could clearly see that Build.Repository.Clean is false in every phase.
Is there any way to fix this?
More info:
Setting system.debug to true produces interesting log:
Querying workspace information.
##[debug]tf workspaces -format:xml "-collection:<tfs-server-url>" -jwt:******** -noprompt
##[debug]No workspace matching *;Project Collection Build Service (<collection-name>) on computer <computer-name> found in Team Foundation Server <tfs-server-url>.
##[debug]<?xml version="1.0" encoding="utf-8"?><workspaces/>
##[debug]Sources directory does not exist or is empty.
##[debug]tf workspaces ws_1_14 -computer:* -format:xml "-collection:<tfs-server-url>" -jwt:******** -noprompt
##[debug]No workspace matching ws_1_14;Project Collection Build Service (<collection-name>) on computer * found in Team Foundation Server <tfs-server-url>.
##[debug]Deleting: '/home/<user>/agent/_work/1/s'.
##[command]tf workspace -new -location:local -permission:Public ws_1_14 "-collection:<tfs-server-url>" -jwt:******** -noprompt
Workspace 'ws_1_14' created.
But when I login to that machine and run these commands myself (without -jwt:... -noprompt) -- I get correct information about ws_1_14 workspace. Agent is being executed as daemon/service created via sudo ./svc.sh install; sudo ./svc.sh start. Which means problem is somewhere in that daemon's environment.
This happens because my hostname was FQDN (instead of shortname). It is an existing bug.
Solution is to change hostname to be short and without dots(e.g. sudo hostnamectl set-hostname shortname) and run build again (it will recreate workspace with short hostname in Computer column) and all subsequent builds should work fine.

Jenkins couldn't recognize Python run from .BAT file

I'm a beginner to Jenkins, and trying to run a small Python code from Jenkins batch command for Windows.
However, the build run throws below error:
Running as SYSTEM
Building in workspace C:\Program Files (x86)\Jenkins\workspace\PythonProject1
[PythonProject1] $ cmd /c call C:\Windows\TEMP\jenkins7865401366299588301.bat
C:\Program Files (x86)\Jenkins\workspace\PythonProject1>cd C:\Users\Ben\Desktop\py
C:\Users\Ben\Desktop\py>python C:\Users\Ben\Desktop\py\for.py
'python' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\Ben\Desktop\py>exit 9009
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
Python is installed in my machine and is declared in Environment Variable too. What am I missing?
"Running as SYSTEM" means the Jenkins service is not running with your account, but the Windows system account, used as a service account.
That means you need to add python path to the system environment variables, not the user ones.

Jenkins can't find make.exe

I'm trying to install jenkins on windows and I have Cygwin.
I provided the bash.exe path to jenkins and add a job which executes a .sh file.
The output is like:
Building in workspace C:\Program Files (x86)\Jenkins\workspace\Build_Release
[Build_Release] $ C:\cygwin64\bin\bash.exe -xe C:\WINDOWS\TEMP\jenkins8276366787192439492.sh
+ cd /cygdrive/d/01-Avelabs/001-Projects/001-VGTT/001-Repos/P2.4.0.5/host/AdasHost/Application/
+ ./BuildHost.sh
./BuildHost.sh: line 2: make: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
What am I missing?
To get you going (the problem is not obvious but it should be easy enough to debug): Add a "set" command at the top of the script to dump the environment variables, including the PATH. You will very likely find that PATH is not in any of the folders listed in the value of the PATH env var. (You could also put simply, "echo $PATH".)
Some possibilities:
When I start bash in Windows I typically inherit the Windows path, but not the Linux path: /cygdrive/c/windows/system32 is included, but /bin is not. So, even basic Linux commands like "ls" result in "command not found" errors. I'll typically start a bash session with "export PATH=/bin:$PATH" to get around this.
Even if you initialize the path with a .bash_profile script, the user under which Jenkins is executing is probably not executing the same initialization script.
Finally - and not meaning to say "Is it plugged in? - but: I ran a clean Cygwin install and did not get make by default. So be sure it is included in /your/ installation!

Running a Windows batch file in Jenkins

I trying to run my Tests cases for a project in Jenkins through DOS Command line on Windows server . I am using Jenkins ver. 1.559.
I am trying to run a Windows batch file through a Jenkins job that has the java command.
Under the "Build" section >> "Execute Windows Batch command" >> Command: call E:\Jenkins\App\UnitTests\App_UnitTests.bat
Save and Build the job.
I am getting an error and here is my Console Output
C:\Program Files (x86)\Jenkins\jobs\App Test Cases\workspace>java.exe -cp "E:\Jenkins\App\PPS\App\bin\;E:\Jenkins\App\PPS\App\lib\junit-4.10.jar;E:\Jenkins\App\PPS\App\lib\*.jar;" org.junit.runner.JUnitCore com.omnitracs.fra.junit.EventTests
'java.exe' is not recognized as an internal or external command, operable program or batch file.
C:\Program Files (x86)\Jenkins\jobs\App Test Cases\workspace>PAUSE
Press any key to continue . . .
C:\Program Files (x86)\Jenkins\jobs\App Test Cases\workspace>EXIT
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
The java command runs fine outside Jenkins.
I have set the JAVA_HOME for the local user and also the PATH variable to point to where java.exe is.
What am I doing wrong? Please help.
For a windows environment, there is some extra configuration needed for more advanced builds. Ultimately you have two options
From Jenkins, The Definitive Guide:
This basic installation will work fine in a simple context, but you
will often need to fine-tune your service. For example, by default,
the Jenkins service will be running under the local System account.
However, if you are using Maven, Jenkins will need an .m2 directory
and a settings.xml file in the home directory. Similarly, if you
are using Groovy, you might need a .groovy/lib directory. And so on.
To allow this, and to make testing your Jenkins install easier, make
sure you run this service under a real user account with the correct
development environment set up. Alternatively, run the application as the
system user, but use the System Information page in Jenkins to check
the /Users/johnsmart/Projects/Books/jenkins-thedefinitive- guide
directory, and place any files that must be placed in the user home
directory here....
To configure your Jenkins server to run under a service account (The suggested option), Install Jenkins as a service, and under the services properties set the log on user info.

Parameterized build Jenkins

I have configured a job in Jenkins and checked "This build is parameterized" option. The parameter name I have given is "My_Param". The Jenkins is installed in the server machine. So I access the Jenkins dashboard through http://<servername>:8080/ In the Build part, I have to call a script by opening cygwin. So I write
#!C:\cygwin\bin\bash --login -i
./build/myscript.sh -full
After the build is completed, I want to move the files to another new directory prefix with Output, This directory name is the parameter I intend to pass. so I write
mkdir /cygdrive/c/users/admin/Ouput$My_Param
I run the build and pass param as first
But, the directory is created as Output in the server machine and not as Outputfirst
Since you noted you use cygwin, I understand the server is on windows.
Try parameter windows style environment variable: %My_Param% or linux: ${My_Param}
I hope this helps.

Resources