Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating C# scripts and references from ScriptCS to dotnet script #2035

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions dictionary-octopus.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,74 @@
actionid
apikey
apikeys
argparse
astro
bootstrap
bootstrapped
bootstrapper
bufio
COMPUTERNAME
createartifact
cryptodome
cscfg
cspkg
csvfile
cutover
datetime
dateutil
deallocate
deallocated
deploymentprocess
deploymentprocesses
DONTVALIDATEPATH
echoerror
elif
environmentids
eprintfn
Fargate
fieldnames
filedata
FIPS
getenv
hasattr
Hashtable
HKEY
HKLM
hotfix
hotfixes
HSTS
icontains
IGNORECASE
includesystem
ioutil
Itoa
ITSM
jwks
kustomization
kustomize
libraryset
librarysets
libraryvariablesets
lifecycles
Linq
lstrip
machinepolicies
machinepolicy
maxage
mozroots
msiexec
MTTR
Netscaler
nologs
noninteractive
notcontains
NTLM
nupkg
O_WRONLY
Octo
octobak
Octopub
octopusartifact
octopusdeploy
octopusid
octopuslabs
Expand All @@ -45,27 +80,65 @@ OIDC
onlylogs
passout
pkcs
printfn
printhighlight
Println
printverbose
printwait
printwarning
PROGRAMFILES
projectgroup
projectgroups
projecttriggers
querystring
quickstart
reprioritize
reprovisioned
reprovisioning
RSASSA
rstrip
Runbook
runbook
runbookprocesses
runbookruns
runbooks
runbooksnapshot
runbooksnapshots
runbooksnapshottemplate
Schannel
scopeduserrole
scopeduserroles
SIEM
signingkeys
Sprintf
sthumb
strconv
struct
swaggerui
systemprofile
tabpanel
tagset
tagsets
Tasklogs
Trivy
typeof
unmarshal
upgradelog
upgrader
urllib
userrole
userroles
utcnow
variableset
Voltron
WCAG
webfonts
WEBSVR
WIXUI
woah
workertools
writeheader
writerow
xlarge
xmark
xvzf
14 changes: 7 additions & 7 deletions src/pages/docs/deployments/custom-scripts/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
layout: src/layouts/Default.astro
pubDate: 2023-01-01
modDate: 2023-01-01
modDate: 2023-10-11
title: Custom scripts
description: Custom scripts allows you to script anything you want using PowerShell, ScriptCS, F#, Python, or Bash.
description: Custom scripts allows you to script anything you want using PowerShell, Dotnet Script, F#, Python, or Bash.
navOrder: 120
---

Expand All @@ -16,7 +16,7 @@ Octopus supports the following scripting environments:
- PowerShell scripts (.ps1)
- Bash scripts (.sh)
- Python scripts (.py)
- C# scripts (.csx) using [ScriptCS](https://github.com/scriptcs/scriptcs)
- C# scripts (.csx) using [dotnet-script](https://github.com/dotnet-script/dotnet-script)
- F# scripts (.fsx)

Octopus can run these scripts on almost any operating system as long as the script runtime is installed and configured correctly.
Expand Down Expand Up @@ -66,13 +66,13 @@ The precise details depend on the context within which your script is running, h
4. Any artifacts published by your scripts are transferred back to the Octopus Server.
5. The temporary work directory is cleaned up.

### Working directories {#Customscripts-Workingdirectories}
### Working directories

When Calamari executes your scripts, it does so within the context of a working directory. The working directory is a temporary location stored under the home folder you configure when setting up a deployment target or worker.

If you're executing a script contained within a package, the package contents will be uncompressed and copied to this directory, but the working directory is the directory containing the script within it. After the script has finished executing, the working directory will be cleaned up. Learn about [copying the contents of the working directory](/docs/support/copy-working-directory).

### Security and permissions {#Customscripts-Securityandpermissions}
### Security and permissions

When scripts are executed, it is in the context of the account that the Tentacle agent or SSH session is running as. Learn about [running Tentacle as a different user account](/docs/infrastructure/deployment-targets/tentacle/windows/running-tentacle-under-a-specific-user-account).

Expand All @@ -88,7 +88,7 @@ For example, when Calamari invokes PowerShell.exe, it uses the `Unrestricted` ex

Learn about [script integrity](/docs/security/script-integrity).

### Developing and testing scripts {#Customscripts-Testingscripts}
### Developing and testing scripts

We recommend the following approaches for developing and testing your scripts, in order of preference:

Expand All @@ -104,7 +104,7 @@ We recommend the following approaches for developing and testing your scripts, i
1. If you are using PowerShell, Octopus has built-in support for PowerShell debugging. Learn about [debugging PowerShell scripts on remote machines using Octopus](/docs/deployments/custom-scripts/debugging-powershell-scripts/debugging-powershell-scripts-on-remote-machines).
2. For all scripting languages, you can tell Octopus to preserve the script and its entire working directory so you can run it interactively. Learn about [copying the working directory](/docs/support/copy-working-directory).

### Scripts that block deployments {#Customscripts-Scriptsthatblockdeployments}
### Scripts that block deployments

Sometimes a script launches a service or application that runs continuously. In this case the script does not complete until the application is terminated. When the script is run in an Octopus process, the Octopus task will continue executing until the script exits. In most cases this is undesirable. In order to avoid this behavior the service or application should be launched in a separate process or session, allowing the rest of the process to continue executing. For example:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: src/layouts/Default.astro
pubDate: 2023-01-01
modDate: 2023-07-18
modDate: 2023-10-11
title: Logging messages from scripts
description: When your scripts emit messages Octopus will display the messages in the Task Logs at the most appropriate level for the message.
navOrder: 50
Expand Down Expand Up @@ -30,10 +30,10 @@ Write-Error "This will be logged as an Error and may cause your script to stop r
Console.WriteLine("This will be logged as Information");
Console.Out.WriteLine("This will be logged as Information too!");
Console.Error.WriteLine("This will be logged as an Error.");
Octopus.WriteVerbose("Verbose!!!");
Octopus.WriteHighlight("This is a highlight");
Octopus.WriteWait("Deployment is waiting on something");
Octopus.WriteWarning("Warning");
WriteVerbose("Verbose!!!");
WriteHighlight("This is a highlight");
WriteWait("Deployment is waiting on something");
WriteWarning("Warning");
```

</details>
Expand Down Expand Up @@ -96,7 +96,7 @@ Progress messages will display and update a progress bar on your deployment task
<details data-group="deployments-custom-scripts-logging-messages">
<summary>PowerShell</summary>

```ps PowerShell
```powershell
Update-Progress 10
Update-Progress 50 "Woah, we're halfway there!"
```
Expand All @@ -106,8 +106,8 @@ Update-Progress 50 "Woah, we're halfway there!"
<summary>C#</summary>

```csharp
Octopus.UpdateProgress(10);
Octopus.UpdateProgress(50, "Woah, we're halfway there!");
UpdateProgress(10);
UpdateProgress(50, "Woah, we're halfway there!");
```

</details>
Expand All @@ -133,8 +133,8 @@ Octopus.updateProgress 50 "Woah, we're halfway there!"
<summary>Python3</summary>

```python
updateprogress(10)
updateprogress(50, 'Woah, we\'re halfway there!')
update_progress(10)
update_progress(50, 'Woah, we\'re halfway there!')
```

</details>
Expand Down Expand Up @@ -176,7 +176,7 @@ let updateProgress (percentage: int) message =
def encode(value):
return base64.b64encode(value.encode('utf-8')).decode('utf-8')

def updateprogress(progress, message=None):
def update_progress(progress, message=None):
encodedProgress = encode(str(progress))
encodedMessage = encode(message)

Expand All @@ -188,12 +188,12 @@ def updateprogress(progress, message=None):
<summary>Bash</summary>

```bash
function encode_servicemessagevalue
function encode_service_message_value
{
echo -n "$1" | openssl enc -base64 -A
}

echo "##octopus[progress percentage='$(encode_servicemessagevalue "$1")' message='$(encode_servicemessagevalue "$2")']"
echo "##octopus[progress percentage='$(encode_service_message_value "$1")' message='$(encode_service_message_value "$2")']"
```

</details>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/docs/deployments/custom-scripts/output-variables.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: src/layouts/Default.astro
pubDate: 2023-01-01
modDate: 2023-01-01
modDate: 2023-10-11
title: Output variables
description: Your scripts can emit variables that are available in subsequent deployment steps.
navOrder: 70
Expand Down Expand Up @@ -31,7 +31,7 @@ Set-OctopusVariable -name "AppInstanceName" -value "MyAppInstance"
<summary>C#</summary>

```csharp
Octopus.SetVariable("AppInstanceName", "MyAppInstance");
SetVariable("AppInstanceName", "MyAppInstance");
```

</details>
Expand Down Expand Up @@ -74,7 +74,7 @@ $appInstanceName = $OctopusParameters["Octopus.Action[Determine App Instance Nam
<summary>C#</summary>

```csharp
var appInstanceName = Octopus.Parameters["Octopus.Action[Determine App Instance Name].Output.AppInstanceName"]
var appInstanceName = OctopusParameters["Octopus.Action[Determine App Instance Name].Output.AppInstanceName"]
```

</details>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: src/layouts/Default.astro
pubDate: 2023-01-01
modDate: 2023-01-01
modDate: 2023-10-11
title: Passing parameters to scripts
description: Octopus can pass parameters to your custom script files for any of the supported scripting languages.
navOrder: 40
Expand Down Expand Up @@ -43,7 +43,7 @@ You can define your parameters in the **Script Parameters** field using the form
Don't forget to correctly delimit your parameters correctly for the scripting engine. In the example above we have surrounded the parameter value in double-quotes to handle cases where the Environment Name has spaces: `"#{Octopus.Environment.Name}"`
:::

## Passing parameters to PowerShell scripts {#Customscripts-PassingparameterstoPowerShellscripts}
## Passing parameters to PowerShell scripts

You can pass parameters to PowerShell scripts as if you were calling the script yourself from PowerShell, using positional or named parameters.

Expand All @@ -66,9 +66,9 @@ Param (
Write-Host "$Environment storage path: $StoragePath"
```

## Passing parameters to C# scripts {#Customscripts-PassingparameterstoC#scripts}
## Passing parameters to C# scripts

You can pass parameters to C# scripts [as described here for the ScriptCS engine](https://github.com/scriptcs/scriptcs/wiki/Pass-arguments-to-scripts). ScriptCS only supports positional parameters.
You can pass parameters to C# scripts [as described here for the dotnet-script engine](https://github.com/dotnet-script/dotnet-script#passing-arguments-to-scripts).

**Script Parameters in Octopus**

Expand All @@ -79,12 +79,12 @@ You can pass parameters to C# scripts [as described here for the ScriptCS engine
**Usage in C# script**

```csharp
var environment = Env.ScriptArgs[0]
var storagePath = Env.ScriptArgs[1]
var environment = Args[0]
var storagePath = Args[1]
Console.WriteLine("{0} storage path: {1}", environment, storagePath);
```

## Passing parameters to Bash scripts {#Customscripts-PassingparameterstoBashscripts}
## Passing parameters to Bash scripts

You can pass parameters to Bash scripts [as described in Bash manual.](https://www.gnu.org/software/bash/manual/bash.html#Positional-Parameters)

Expand All @@ -102,7 +102,7 @@ storagePath="$2"
echo "$environment storage path: $storagePath"
```

## Passing parameters to F# scripts {#Customscripts-PassingparameterstoF#scripts}
## Passing parameters to F# scripts

You can pass parameters to FSharp scripts [as described by the F# documentation.](https://docs.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-interactive/#using-the-fsi-object-in-f-code)

Expand All @@ -120,7 +120,7 @@ let storagePath = fsi.CommandLineArgs.[2]
printfn "$s storage path: $s" environment storagePath
```

## Passing parameters to Python3 scripts {#Customscripts-Passingparameterstopythonscripts}
## Passing parameters to Python3 scripts

You can pass parameters to python scripts [as described by the python documentation.](https://docs.python.org/3/tutorial/interpreter.html#argument-passing)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: src/layouts/Default.astro
pubDate: 2023-01-01
modDate: 2023-01-01
modDate: 2023-10-11
title: Reference files within a package
description: How to reference files within a package.
navOrder: 80
Expand Down Expand Up @@ -53,9 +53,9 @@ Get-Content ".\subfolder\file.txt"

```csharp C#
// in pre-deploy, in post-deploy if custom installation directory has not been defined
var extractPath = Octopus.Parameters["Octopus.Action.Package.InstallationDirectoryPath"];
var extractPath = OctopusParameters["Octopus.Action.Package.InstallationDirectoryPath"];
// if a custom installation directory has been defined
var customPath = Octopus.Parameters["Octopus.Action.Package.CustomInstallationDirectory"];
var customPath = OctopusParameters["Octopus.Action.Package.CustomInstallationDirectory"];
// original extract path,
Console.WriteLine(File.ReadAllText(extractPath + @"\subfolder\file.txt"));
// or when a custom installation directory has been defined,
Expand Down
Loading