Greetings,
I am trying to automate the deployment of our software and was trying to use Powershell to run a script post my deployment to point a group of existing Jobs to the folder of the new version of the software. Basically, when I open VisualCron I have something like this:
- Group : CUSTOMER on SERVER (2 items)
1) JOB1
2) JOB2
If I double click the Job, then the Task list, there's only one task which is to execute an executable file. This file is located usually in a folder with this structure:
C:\Program Files (x86)\COMPANY\CUSTOMER\VERSION1.0\EXECUTABLE.exe
Everytime I do a new deployment of our software, I will have it deployed to a different folder, like this:
C:\Program Files (x86)\COMPANY\CUSTOMER\
VERSION1.1\EXECUTABLE.exe
What I was trying to do via Powershell was to connect to the VisualCron Server and find the relevant jobs, and then set their Execute.CmdLine property to the new folder. I checked the documentation of the API and managed to get this script together, for testing purposes, which I am running through Powershell ISE:
function Get-VCAPIPath
{
$programFilesPath = if (${Env:PROCESSOR_ARCHITECTURE} -eq 'x86') { ${Env:ProgramFiles} } else { ${Env:ProgramFiles(x86)} }
Join-Path $programFilesPath VisualCron\VisualCronAPI.dll
}
function Get-VCServer
{
[CmdletBinding()]
param ([string]$ComputerName,
[int]$Port,
[System.Management.Automation.PSCredential]$Credential)
$apiPath = Get-VCAPIPath
if (!(Test-Path $apiPath)) { Throw "VisualCron does not appear to be installed. API library not found at `"$apiPath`"." }
[Reflection.Assembly]::LoadFrom($apiPath) | Out-Null
$conn = New-Object VisualCronAPI.Connection
$conn.Address = if ([String]::IsNullOrEmpty($ComputerName)) { ${Env:COMPUTERNAME} } else { $ComputerName }
if (!($credential -eq $null))
{
$conn.UseADLogon = $true
$netcred = $credential.GetNetworkCredential()
$conn.UserName = $netcred.UserName
$conn.Password = $netcred.Password
}
$client = New-Object VisualCronAPI.Client
$client.Connect($conn)
}
function Get-AllVCJobs
{
[CmdletBinding()]
param ([string]$ComputerName,
[int]$Port,
[System.Management.Automation.PSCredential]$Credential,
[switch]$Active)
$ps = New-Object Collections.Hashtable($psBoundParameters)
$ps.Remove('Active') | Out-Null
$server = Get-VCServer @ps
$server.Jobs.GetAll() `
| ? { !($Active) -or $_.Stats.Active } `
| Add-Member ScriptMethod Start { $server.Jobs.Run($this, $false, $false, $false, $null) }.GetNewClosure() -PassThru
}
$jobs = Get-AllVCJobs
Foreach ($job in $jobs)
{
if ($job.Group -eq 'CUSTOMER on SERVER')
{
Write-Host $job.Id
Write-Host $job.Name
Write-Host $job.Group
$tasks = $job.Tasks
Foreach ($task in $tasks)
{
$newPath = 'C:\Program Files (x86)\COMPANY\CUSTOMER\VERSION1.1\'
$newTaskExecuteCmdLine = $newPath + 'EXECUTABLE.exe'
$task.Execute.CmdLine = $newTaskExecuteCmdLine
# I MIGHT BE MISSING SOMETHING HERE TO "SAVE" THE CHANGE?!?!
}
}
}
The above script allows me to navigate the tree, get all the relevant jobs and navigate through their tasks but it is not persisting this to the server and that's what I'm missing. I've read the API documentation and couldn't find one single example on how to persist this, plus it seems that all the samples in there are for read-only purposes.
Can you please advise?
Thanks and Regards,
Pedro Silva
Edited by moderator
2016-05-19T16:16:00Z
|
Reason: Not specified