Offline Deployment package script giving error if run remotely

Hi Team,

We have setup deployment to an offline package drop for one of our environments. After the drop has been performed, and the files have been copied to the server, we have a robocopy script which deploys the offline package from octopus server to shared drive.

Then, we have another batch job which is executed from the deploy server to individual web servers. Instead, of manually executing the ocotpus created batch file which will execute all the deployment steps.
We wanted to run a ps1 script from one web server say from web1 -Invoke command -FilePath “<path_to_drop>/environment/project/release/machineName.project.deploymentId.ps1” remotely to web2,3,4… so on

Note - The above File path does contain all the necessary folder such as Calalmari, Variables, Scripts and bat and ps1 files to execute the deployment.

I created Invoke command ps1 script, to run from one web server and I am getting a below error :

PS F:> cd F:\Robocopy
PS F:\Robocopy> .\DeploymentComponentApiExecutionScript.ps1
The module ‘Calamari’ could not be loaded. For more information, run ‘Import-Module Calamari’.
+ CategoryInfo : ObjectNotFound: (Calamari\Calamari.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoLoadModule
+ PSComputerName : oeuncmsweb2

Do you have any pointers, Will we be able to execute <path_to_drop>/environment/project/release/machineName.project.deploymentId.ps1 script remotely ?

Also, we cannot do tentacle based deployment on PROD due to network and security issues at the moment. Hence, going with offline package drop approach.

Please help me here as this urgent and affecting my timelines to complete the task. Thanks in advance !

Bhavesh

Hi Bhavesh,

Thanks for reaching out. When using offline package drops, the deployment can only be run via the deployment script created by Octopus as described here. This script acts as a bootstrapper as it knows the location of calamari (which is required for all deployment steps) and all the other components like variables. Are you able to copy the entire offline drop package to all the web servers (web1,2,3,4) and then execute the deployment script remotely from say web1?

I hope I have understood your scenario correctly, please let me know if you have any further questions.

Kind Regards,
Tom W

Hey Tom,
Good Morning !

Yes, I referred the same link which you shared for Octopus offline package drop.
Also, to answer your question, Yes i am copying the entire offline drop folder to all web servers and file path is also the same. Please see below the folder which is being copied.

Is something wrong with the script which i am trying to run ?

Hi Bhavesh,

Thanks for clarifying that, are you able to run the scripts on all the web servers manually (i.e log into them and execute the deployment script)?
It could be related to how you are executing the remote script, are you able to provide the command/script you are using to execute the deployment script remotely?

Kind Regards,
Tom W

Hi Bhavesh,

Just wanted to reach out and see if you were able to get the remote scripts working, Please reach out if you require assistance.

Kind Regards,
Tom W

Hi Tom,
Thanks for getting back to me. Yes, I am able to run the script remotely form one of the web server to others.

Please find the snippet for future refrence

$Username=“domain\username”
$WebServers = @(“server1”,“server2”,“server3”,“server4”,“server5”,“server6”,“server7”,“server8”)
Invoke-Command -Credential $Username
ForEach ($RemoteComputer in $WebServers)
{
Try
{
Invoke-Command -ComputerName $RemoteComputer -ScriptBlock {
& “<path_to_drop>\environment\project\release\Calamari\Calamari.exe” run-script -script “<path_to_drop>\environment\project\release\machineName.project.deploymentId.ps1”
} -ErrorAction Stop
}
Catch
{
Add-Content Unavailable-Computers.txt $RemoteComputer
continue
}
Add-Content Success-ComponentApiExecutionScript-$RemoteComputer.txt $result
}

Also, I had one more question:

We are trying to deploy the offline package from octopus server (from a particular path on octopus server) to a shared drive, using a powershell script added as one of the process in octopus project.
I am getting an error in the octopus console - The remote script failed with exit code 3
But, the package gets deployed to target drive.

Do you know, how to make changes in the console, if .ps1 scripts is actually getting executed and is sucsess ?

Hi Bhavesh,

I’m glad to hear you got the script working.
In regards to the The remote script failed with exit code 3 error, its hard to tell exactly why the script failed without any logs, it sounds like the script partially worked, as it was able to copy the files, however something in the script set the exit code to 3, causing Octopus to think something went wrong. are you able to see anything in the logs that might indicate a error for any of the steps in your script?

Kind Regards,
Tom

Hey Tom,

Good Morning !

I have checked the Raw Octopus Logs, which does not give me exact root cause why the script failed, just says :

*Log File : C:\Robocopy\RobocopyLogs\2018-05-18T10.54.46.8832507+00.00_robocopy_output__hofstoroeuncms.file.core.windows.net.txt

10:54:53 Info | The last PS command failed with result: 1

10:54:53 Verbose | Process C:\Windows\system32\WindowsPowershell\v1.0\PowerShell.exe in C:\Octopus\Work\20180518105440-13096-46 exited with code 1

10:54:53 Verbose | Updating manifest with output variables

10:54:53 Verbose | Updating manifest with action evaluated variables

10:54:53 Fatal | The remote script failed with exit code 1

10:54:53 Verbose | at Octopus.Server.Orchestration.Targets.Scripting.ScriptResult.EnsureSuccessful()

               >       at Octopus.Server.Orchestration.ServerTasks.Deploy.Steps.Script.ServerScriptActionHandler.Execute(ActionCommand command, Machine machine)

               >       at Octopus.Server.Orchestration.ServerTasks.Deploy.DeploymentTaskController.<>c__DisplayClass30_0.<ExecuteActionAndInitLoggingContext>b__0()

               >       at Octopus.Server.Orchestration.ServerTasks.Deploy.DeploymentTaskController.ExecuteWithTransientErrorDetection(Action action, Machine machine)

               >       at Octopus.Server.Orchestration.ServerTasks.Deploy.DeploymentTaskController.ExecuteActionAndInitLoggingContext(PlannedStep step, Machine machine, PlannedAction action)*

I have checked the Powershell script log file, which says that all the files copied successfully. Although, I am getting error in octopus console with exit code - 3 or 1 at times.

Hence, I have added a check (see below) in the .ps1 script step :

if ($LastExitCode -lt 8)

{

Write-Host “The last PS command executed successfully”

$LastExitCode = 0

}

Please, let me know, if this is a fine approach and should be way forward to avoid error in GUI.

Thanks & Regards,

Bhavesh

Technology Analyst

M: +44 7435788651

cid:image001.gif@01D10BEE.B53DC020

Upcoming Holidays / Leaves – 28th May and 22nd June to 27th June 2018

Hi Bhavesh,

if you are able to check $LastExitCode and set it to 0 if it is -3 or 1, then the error code must be set from one of the lines in your script, the approach of overriding $LastExitCode is fine, if the end result of the deployment looks fine then that might be sufficient. However I would recommend trying to isolate the specific PowerShell command that is setting $LastExitCode to either 1 or -3, you could try putting the if statement around different bits of the script, checking the exit code as you progress through. If you are able to isolate it, you can then search out for the documentation on that command and hopefully it will specify the meaning of the exit codes being set.

Kind Regards,
Tom

Hi Tom,

Thanks for the below suggestions and approach.

I will try the debug as you said.

Meanwhile, as the end result of deployment looks fine so I am setting the $LastExitCode to 0

Thanks & Regards,

Bhavesh

Technology Analyst

M: +44 7435788651

cid:image001.gif@01D10BEE.B53DC020

Upcoming Holidays / Leaves – 22nd June to 27th June 2018 and 3rd July 2018

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.