Skip to content

dynamically assign drive letter to WORKSPACE env var#8398

Merged
colinsurprenant merged 1 commit intoelastic:masterfrom
colinsurprenant:fix/long_path
Sep 29, 2017
Merged

dynamically assign drive letter to WORKSPACE env var#8398
colinsurprenant merged 1 commit intoelastic:masterfrom
colinsurprenant:fix/long_path

Conversation

@colinsurprenant
Copy link
Copy Markdown
Contributor

@colinsurprenant colinsurprenant commented Sep 26, 2017

Try to assign a drive letter to the WORKSPACE env var to shorten the current path to avoid hitting the 260 chars limits in Windows.

Strategy:

  • first loop through the list of subst drives to see if WORKSPACE was already assigned to a drive and reuse it
  • otherwise try to subst the first free drive letter to WORKSPACE

The idea is to avoid just assigning new drive letters blindly since this is a long-running server. The number of used drive letters will top at the number of unique WORKSPACE paths which shoud avoid depletion.

Relates to #7767

@jordansissel
Copy link
Copy Markdown
Contributor

I am +1 on this proposal (using subst to map a drive letter to a path) but I haven't tested.

setlocal enabledelayedexpansion

setlocal
if not exist %WORKSPACE% (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a current working in batch (e.g. pwd) that could be used instead of a the Jenkins environment variable ? (It is a bit kinder to Windows developers )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, once we know this work we can certainly improve it to not make it Jenkins specific somehow... or have some sensible fallback defaults.


setlocal
if not exist %WORKSPACE% (
echo Error: env var WORKSPACE must be defined
Copy link
Copy Markdown
Contributor

@jakelandis jakelandis Sep 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm...i ran into this error while testing, but didn't get the echo to print in the cmd console.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh ok. do you mean testing in Jenkins? If so maybe WORKSPACE is not defined then? but it should be per the Jenkins build env var list page!?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, i meant running locally I did not define %WORKSPACE% and had to review the code to understand the issue since the echo didn't print.

I haven't tested in Jenkins yet.

Copy link
Copy Markdown
Contributor

@jakelandis jakelandis Sep 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to fix it. Note - the following code works from cmd, but seems to not work from PS, Jenkins is not PS, and I think .bat files are default executed by cmd.

if "%WORKSPACE%"=="" ( 
  echo Error: env var WORKSPACE must be defined
  exit /B 1
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed this.

@colinsurprenant colinsurprenant changed the title dynamically assign drive letter to WORKSPACE env var [WIP] dynamically assign drive letter to WORKSPACE env var Sep 27, 2017
@colinsurprenant
Copy link
Copy Markdown
Contributor Author

I added WIP in the title because there will certainly be some back & forth with this since I did not test it under Jenkins.

exit /B 1
)

:: see if %WORKSPACE% is alread mapped to a drive
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented out

 rem %RAKEPATH% test:install-core
 rem %RAKEPATH% test:core

and ran this a few times (in cmd) to test this, and the drives kept incrementing every time i ran it. (it did succesfully skip c:\ however)

I am not familiar with the voodoo here, but trying to echo %%G or %%~sfH seemed to echo the literals not what I assume they are expanding to ?
image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh .. this is weird. I tested the "reuse" bits in isolation and it worked in my 2012 box ... but I did not test when included in the user_tests.bat. will do, thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed with latest set of commits
image

@jakelandis
Copy link
Copy Markdown
Contributor

I will readily admit that I don't fully understand the line by line details of the batch scripting. But I don't think that is needed here it since it either works or it doesn't.

I worked with @colinsurprenant to get this fully tested in on our Windows 2012 and Windows 2016 boxes and all looks good.

  • All windows tests pass on Windows 2012 and 2016.
  • Drive letters are auto assigned and incremented properly.
  • Drive letters are re-used across runs for the same branch.
  • Different branches use different drive letters.

LGTM

fix underfined env var check

check for defined JRUBYSRCDIR env var

check for errorlevel after launching rake tasks

cosmetics

call rake

keep original path

cosmetic

cosmetic
@colinsurprenant colinsurprenant merged commit e172341 into elastic:master Sep 29, 2017
@colinsurprenant
Copy link
Copy Markdown
Contributor Author

rebased and merged into 5.5, 5.6, 6.0, 6.x and master.

@colinsurprenant colinsurprenant changed the title [WIP] dynamically assign drive letter to WORKSPACE env var dynamically assign drive letter to WORKSPACE env var Sep 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants