The following powershell should give you some clues. The idea with this sort of thing is to make it as noisy as possible so you give yourself good clues if it fails
<#Example powershell script, show how to fire a daemon, logon load a workspace , process JSON
logoff and kill the daemon
#>
param (
[string] $wspaceDir = "C:\Temp\exp1\loadDir",
[string] $wspaceName = "scmParallelTestWspace1",
[string] $scmLoc= "C:\RTC Eclipse Client\ALM-R12-RTC-Client-Win64-6.0.4-base\jazz\scmtools\eclipse\scm.exe",
[string] $lscmLoc= "C:\RTC Eclipse Client\ALM-R12-RTC-Client-Win64-6.0.4-base\jazz\scmtools\eclipse\lscm",
[string] $rtcUser="userId",
[string] $rtcPasswordFile="C:\UsersDirectory\notObvious.txt",
[string] $portNumForDaemon="61938"
)
function processErrorCode([int] $thisError) {
#scm has a ton of error codes you can process here
#try to hopefully recover from the errors, error code reminder below - collapse by default
<#
Scripted execution of Rational Team Concert source control command line tools can make use of the following exit status codes to make execution or flow control decisions.
Value Status
0 The command completed successfully.
1 There was a syntax error on the command line.
2 The client could not connect to the named repository URI with the credentials supplied by the user.
3 A failure occurred for an unknown reason
4 An internal error indicating that a subcommand could not be loaded.
5 The sandbox is misconfigured (its root could not be found, or is not shared).
6 A resource name collision was detected in the sandbox. An unshared resource in the sandbox has the same name as a shared resource in the repository workspace. This prevented the shared resource from being loaded.
7 A failure occurred due to an unknown internal error
8 The requested operation could not be completed because the sandbox is out of sync with the repository workspace. The user should reload or re-share the sandbox.
9 The requested operation could not be completed because a selector (name, alias, or UUID) supplied by the user either does not match enough items, or matches too many.
10 not used
11 There is a resource conflict in one or more repository workspaces accessed by the subcommand. The user must resolve those conflicts before continuing.
12 An unknown subcommand name was used.
13 reserved (OSGi exception)
14 A request to move a resource failed because the target exists and is unshared, or the target path is invalid.
15 Remote data changed during command execution. Re-run the command.
16 The requested operation could not be completed because it would introduce a gap into the change set history.
17 The requested operation was blocked by Team Process.
18 The requested operation failed because the user lacked one or more repository permissions. The message returned provides more information about the failure.
19 The requested operation could not complete because preconditions were not met.
20 The requested operation attempted to transfer a file that has improper line terminators or encoding.
21 The requested operation could not complete because it would create an n-way conflict in the change set history.
22 The requested operation could not complete because it would create one or more items that have no parent.
23 reserved (OSGi exception)
24 reserved (OSGi exception)
25 One or more specified repository items were not found.
26 Server error.
27 The sandbox is in use by another RCP process (an eclipse GUI or another Rational Team Concert source control command line client).
28 The requested operation could not complete because the repository workspace is misconfigured: the client could not find an item in the repository workspace. The user should verify that any repository workspace paths are correct.
29 The requested operation could not complete because of a license limitation.
30 The requested operation could not complete because but the item's state is inappropriate.
31 The file system daemon didn't receive an initial connection within the alloted amount of time.
32 The communication with the repository timed out.
33 Some of the properties could not be fetched for the specified files.
34 The requested operation cannot continue because there are files that are not checked in.
35 The property could not be set for the specified file.
36 The repository information was incorrectly specified with respect to an item.
37 The change set could not be completed.
38 The suspend operation cannot be performed on the suspended change set.
39 Encountered an IOException.
40 The requested operation could not be completed because the change set is not in history.
41 Service failure encountered when communicating with the repository.
42 Indicates that the mime type could not be set for the specified file.
43 Indicates that the daemon closed the stderror before printing the connection coordinates.
44 Indicates that the specified load rules cannot be processed because it has inaccessible items or has invalid load rules.
45 Indicates that delivering changes would create conflicts in the stream.
46 Indicates that the requested state of the versionable is deleted.
47 Indicates that we could not determine the repository URI for the given repository id.
48 Indicates that a server state mismatch has been detected. This can happen when we try to connect to the server from a daemon which has been active through the server rename process.
49 Indicating the user to rerun the command.
50 Indicates that one or more items are locked in the stream.
51 Indicates that a failure occurred due to an unexpected condition.
52 Indicates that an accept succeeded, but there were no incoming changes, so the workspace remains unchanged.
53 Indicates that a deliver succeeded, but there were no changes to deliver to the repository.
54 Indicates that one or more of the workspaces that are loaded in the sandbox are unreachable; therefore, the output from the status command does not include the status of all the workspaces in the sandbox.
#>
Write-Host "Processing Errorcode $($thisError)"
#the majority of errors cannot be recovered from so test for those that can then exit with the code if there is no clause
switch($thisError)
{
0 {
#should never get here, indicates successful command
break
}
6 {
#load error, ask the user if they want to force a load
#Note - makes no sense if run remotely obviously
$confirmation = Read-Host "Do you want to force a load?"
if ($confirmation -eq 'y') {
$loadResult = &"$($lscmLoc)" "load" "-r" "jazzhost" "--force" $wspaceName
if ($LastExitCode -ne 0 -and $LastExitCode -ne 6) {
processErrorCode -thisError $LastExitCode
}
break
}
}
52 {
write-host "There were no changes to accept"
break
}
53 {
write-host "There was nothing to deliver"
break
}
#enclose clause in curly brackets if using logic, this clause is for
#errors that don't matter and can be skipped over, probably more than shown here
{ $ -eq 33 -or $ -eq 30} {
break
}
#I think we want to crash out if we get any other errors, but nice to clean up
default {
#logout and clear up then exit
&"$($lscmLoc)" "logout" "-r" "jazzhost"
&"$($scmLoc)" "daemon" "stop" "--port" $portNumForDaemon
exit $thisError
}
}
}
Write-Host "Loading Workspace $($wspaceName)"
#get password from file (put file on a drive only visible to you)
$rtcPass= Get-Content $rtcPasswordFile
#logon and start a daemon for all our actions, needs to be a seperate process or it will lock this one
#NOTE THAT THE daemon has to be started in the same directory as any lscm commands being run, and they need to be lscm commands not scm ones
#not sure this is effective
start-job -scriptblock {
Set-Location "$($args[1])"
&"$($args[0])" "daemon" "start" "$($args[1])" "--port" $args[2]
} -ArgumentList $scmLoc, $wspaceDir, $portNumForDaemon
#fire up scm then wait for 10 seconds to let daemon start up
Start-Sleep -Seconds 10
#currrent directory needs to be the one that scm daemon is running in
#always need to logon should always set a nickname for the session, in this case hard coded to jazzhost
Set-Location "$($wspaceDir)"
&"$($lscmLoc)" "login" "-r" "$($rtcURL)" "-u" "$($rtcUser)" "-P" "$($rtcPass)" "-n" "jazzhost"
# we are assuming that we have a workspace and component to deliver to already
# but to illustrate the possibilities lets check for the existence of a component and a workspace and
# give good error messages if we need to exit
#This will get the current users workspaces
$allWorkspaces = &"$($lscmLoc)" "list" "workspaces" "-c" "$($env:USERNAME)" "-j" "-r" "jazzhost" | ConvertFrom-Json
$testWorkspacePresence = @($allWorkspaces | where { $_.name -eq $wspaceName } )
#Not finding the workspace is an error for us so generate an error and exit
if($testWorkspacePresence.Count -lt 1) {
Write-Host "Can't find workspace $($wspaceName) or it is not owned by you, exiting"
processErrorCode -thisError 1
}
#accept all changes into the repository workspace - reasonable assumption with a script
#but may also want to scope to component or work items, need to process output , use v to make it noisey
#note accept returns a ton of information
$acceptResult= &"$($lscmLoc)" "accept" "-j" "-v" "-t" $wspaceName "-r" "jazzhost"| ConvertFrom-Json
if ($LastExitCode -ne 0) {
processErrorCode -thisError $LastExitCode
}
#load our repository workspace tons of things can go wrong here should process errors
#too much for first example though, note that force is a blunt instrument, if a force is
#required an error will be generated and the user will be asked if that is what they want
$loadResult = &"$($lscmLoc)" "load" "-r" "jazzhost" "--allow" $wspaceName
if ($LastExitCode -ne 0) {
processErrorCode -thisError $LastExitCode
}
#logout and clear up and exit with a success errorlevel of 0
&"$($lscmLoc)" "logout" "-r" "jazzhost"
&"$($scmLoc)" "daemon" "stop" "--port" $portNumForDaemon
Write-Host "Script Completed Normally"
exit 0