[ccnet-user] Environment variable names in lower case

41 views
Skip to first unread message

Arieh Schneier

unread,
Apr 29, 2010, 11:58:31 PM4/29/10
to ccnet-user
Follow on from this thread...
http://groups.google.com.ag/group/ccnet-user/browse_thread/thread/8867958676c818e9#

I have this issue which means we can't update. I tried to narrow down
the version where it was introduced by installing versions and
checking whether it happens or not. it is somewhere between 1.4.2.21 -
23 Dec 08 (which works fine) and 1.4.2.3864 (which doesn't work - env
vars are lowercase). I can't narrow it further as there are no builds
in between on ccnetlive.

To test I created a nant project which calls a batch file which just
calls set:
config file:
<cruisecontrol>
<project name="Test set" queue="settest" queuePriority="1">
<category>settest</category>
<triggers/>
<tasks>
<nant>
<buildArgs></buildArgs>
<buildFile>run.xml</buildFile>
<buildTimeoutSeconds>86400</buildTimeoutSeconds>
<baseDirectory>C:\Program Files\CruiseControl.NET\server\</
baseDirectory>
<executable>C:\Program Files\nant-0.85\bin\nant.exe</executable>
<logger>NAnt.Core.XmlLogger</logger>
<nologo>True</nologo>
<targetList>
<string>run</string>
</targetList>
</nant>
</tasks>
</project>
</cruisecontrol>

run.xml:
<?xml version="1.0"?>
<project name="test" default="build" basedir="Z:">

<description>test NAnt Build Script.</description>

<target name="run" description="">
<exec program="C:\Program Files\CruiseControl.NET\server\Test set
\WorkingDirectory\set.bat" />
</target>
</project>

set.bat:
set


I am guessing it is to do with the changes the ProcessExecutor but
can't actually see what would cause it. The function we use inside the
tool that gets called uses this function to fix the env, maybe you
could do something similar before calling run on the process (so that
it will work out of the box for every executable):

private void FixupEnvironmentVariables()
{
// http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=326163

StringDictionary sd = new StringDictionary();
foreach (string key in
Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine).Keys)
{
sd.Remove(key);
sd.Add(key, key);
}

foreach (string key in
Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User).Keys)
{
sd.Remove(key);
sd.Add(key, key);
}

foreach (string key in
Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process).Keys)
{
if (sd.ContainsKey(key) && !sd[key].Equals(key,
StringComparison.Ordinal))
{

// We have an env var in the process that is in a
different case at the user or machine level.
// Add the correct case version.
// Simply resetting the name will have no effect
because Windows will preserve the case in which
// it was initially created. We must remove it and
then re-add it.
// To remove a environment variable in a process,
you must set the value of it to empty string.
string value =
Environment.GetEnvironmentVariable(key,
EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable(sd[key],
"",
EnvironmentVariableTarget.Process);

// Now set the environment variable using the
correct case.
Environment.SetEnvironmentVariable(sd[key],
value,
EnvironmentVariableTarget.Process);
}
}
}

Thanks in advance,
Arieh

Arieh Schneier

unread,
Jun 3, 2010, 8:56:40 PM6/3/10
to ccnet-user
Has anyone else had a chance to try my test case to see if you can
replicate it?

Thanks,
Arieh

Ales Omahen

unread,
Mar 13, 2015, 3:26:39 AM3/13/15
to ccnet...@googlegroups.com
A little late, but I can confirm the same issue on ccnet 1.6.7981.1.

We are (ab)using ccnet for Android builds using gradle 1.1.0 and NDK v10. The build fails miserably when the Android NDK make file expects "normal" case of shell variables. Looks like make is case sensitive while regular Windows shell scripts are not.

I worked around the issue by hacking the ndk-build.cmd file and pre-pending this bit:

IF DEFINED ccnetproject (
  ECHO
Applying Environment variable hack for CC.NET.
  SET OS2
=%os%
  SET OS
=
  REM SET PATH
=%path%
  SET TEMP2
=%temp%
  SET TEMP
=
)


IF DEFINED ccnetproject
(
  SET OS
=%OS2%
  SET OS2
=
  SET TEMP
=%TEMP2%
  SET TEMP2
=
)


Since shell scripts are case insensitive a temporary copy for OS and TEMP variables is made first and then the lower case variables cleared to un-define them. Next the reverse is done into upper case variables. It feels wrong to do this and modifying the Android NDK seems even more wrong... But the build is now working.

Has this issue been resolved in later releases?

Regards,
Ales.
Reply all
Reply to author
Forward
0 new messages