Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
precondition with variables
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
bswift  
View profile  
 More options Oct 29 2011, 11:44 am
From: bswift <brettsw...@gmail.com>
Date: Sat, 29 Oct 2011 08:44:52 -0700 (PDT)
Local: Sat, Oct 29 2011 11:44 am
Subject: precondition with variables
I'm running a .net project, and am doing some integration tests to the
database.   I want to run mongo both on my CI server (teamcity) and
locally.   The problem is that locally I have a database installed,
and on the server I want it to run in process, or for anyone checking
out the code to not have to install mongo.

What I want to wrap my tests with an initial "StartMongo" task and end
it with a "StopMongo" task.   I'm trying to use preconditions for
this.

My first trial was to set a boolean property, and on the first "Init"
task, see if mongo is running, set that property and use that property
in the preconditions.   It seems like preconditions are evaluated when
the script is loaded, if it's running off a property variable.

I can't use the code that I have here, because the "StopMongo"
precondition will ALWAYS return true.

Any ideas on how I can get this to work?   As you see in the script
below, I have the precondition commented out on the StopMongo task to
output the variable that I want to use to see if mongo is running, it
always evaluates to false.

Thanks!

properties {
 $root_dir = Resolve-Path .
 $test_dir = "$root_dir\test\"
 $lib_dir = "$root_dir\lib\"
 $temp_dir = "$root_dir\temp"

 $solution_name = "ToolRegistry"
 $solution_file = "$solution_name.sln"

 $mongoDb_dir = "$root_dir\temp\data\db\"
 $mongoDbExe = "$root_dir\lib\MongoDbExe\bin\mongod.exe"
 $mongoDbParams = "--dbpath $mongoDb_dir"

 $killMongoProcess = $false

}

#move to functions file
function Get-FrameworkDirectory(){
   $
([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory() )

}

function CheckForRunningMongo{
   ((Get-Process "mongod" -ea SilentlyContinue)) -eq $null

}

task default -depends StartMongo, StopMongo

task StartMongo -Depends Init -precondition { return
CheckForRunningMongo} {
   write-host "starting mongo $mongoDbExe"
   Start-Process -FilePath $mongoDbExe  -ArgumentList $mongoDbParams
   write-host -foregroundcolor green "Mongo Process id :" $mongoPid.Id
   $killMongoProcess = $true

}

task StopMongo {# -precondition  {return CheckForRunningMongo} {
    write-host -foregroundcolor green "Kill Mongo Process?
$killMongoProcess   "
    Stop-Process -processname mongod


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jorge Matos  
View profile  
 More options Oct 30 2011, 11:59 pm
From: Jorge Matos <matos.jo...@gmail.com>
Date: Sun, 30 Oct 2011 22:59:07 -0500
Local: Sun, Oct 30 2011 11:59 pm
Subject: Re: precondition with variables
hmmm pre-conditions are evaluated before a task is executed, not when the script is loaded.

I don't see anything obviously wrong with your script but try this - replace the calls to the "CheckForRunningMongo" function with the code [((Get-Process "mongod" -ea SilentlyContinue)) -eq $null}] or try adding "()" to the end of the function call ["CheckForRunningMongo()"]

I think your precondition code is always returning true because you are not invoking the function and returning a result but simply returning a reference to the function.

But I could be wrong. :)

Sent from my iPhone

On Oct 29, 2011, at 10:44 AM, bswift <brettsw...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bswift  
View profile  
 More options Oct 31 2011, 12:36 am
From: bswift <brettsw...@gmail.com>
Date: Sun, 30 Oct 2011 21:36:20 -0700 (PDT)
Local: Mon, Oct 31 2011 12:36 am
Subject: Re: precondition with variables
I figured it out.

Instead of setting the  $killMongoProcess variable in my "Init" task,
I call it right from within the properties section.

 $killMongoProcess = CheckForRunningMongo

Also -->   if I instead use your suggestion:  CheckForRunningMongo()  -
it complains about the parenthesis because it's looking to parse some
parameters.

Thanks for the help though.

On Oct 30, 9:59 pm, Jorge Matos <matos.jo...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »