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

Add variable enumeration for bash #1441

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

IsaacCalligeros95
Copy link
Contributor

@IsaacCalligeros95 IsaacCalligeros95 commented Feb 13, 2025

Support enumerating variable in bash scripts. This change is based off this 2018 change and will add support for accessing variables in bash scripts as associative arrays. In Powershell this is supported by the OctopusParameters property, in bash this will be backed by octopus_parameters. Details on iterating associative arrays are available here. As an example this can be used with

The implementation for this is based off of the PowerShell implementation of OctopusParameters Decrypt-Variables.

For PowerShell we do the following in C#

  • Base 64 encode the variable name and value with a $ delimiter between them. (This is to make sure all special characters are removed)
  • Encrypt the combined string of all variables (We can a base string and IV)
  • Base64 encode the base string and convert the IV to hex.

These are then string replaced in the PowerShell bootstrap.ps1 script.

The PowerShell bootstrap script does the following:

  • Decodes the IV and Hex
  • Decrypts the whole string
  • Decodes one by one the variable name and values

This works well in Powershell ~3000 variables takes about 1 second in this process.
In base we use Openssl to decode base64 strings, this spins up a process and overall repeating this same process for ~3000 variables takes ~60 seconds.

To work around this I've settled on Hex encoding the variable names, unlike base64 hex encoded strings can be concatenated and decrypted all at once, this also doesn't depend on the openssl process being invoked. In this version I've settled on xxd, and if it's not available we do not populate the octopus_parameters variable. We can handle this ourselves but the implementation is messy and I did run into some issues with encoding/decoding emojis.

Accessing keys

echo ${!example_array[@]}

Accessing values

echo ${example_array[@]}

Accessing a value

echo ${example_array["key1"]}

Combined example.

for key in "${!octopus_parameters[@]}"; do
    value="${octopus_parameters[$key]}"
    echo "Key: $key, Value: $value"
done

After:
image

image

{
return variables.Select(variable =>
{
var variableValue = $@"$(get_octopusvariable ""{variable.Name.Replace("\"", "\\\"")}"")";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far the only case I've found that I have to manually add delimiters to is ". This is because the final generated command has the format:

 declare -grA octopus_parameters=(["Octopus.Agent.ProgramDirectoryPath"]="$(get_octopusvariable "Octopus.Agent.ProgramDirectoryPath")" ["Octopus.Sashimi.ScriptFunctions.Registration"]="$(get_octopusvariable "Octopus.Sashimi.ScriptFunctions.Registration")" ["Octopus.Deployment.Id"]="$(get_octopusvariable "Octopus.Deployment.Id")" ["Octopus.Deployment.Name"]="$(get_octopusvariable "Octopus.Deployment.Name")" ["Octopus.Deployment.Created"]="$(get_octopusvariable "Octopus.Deployment.Created")" ["Octopus.Deployment.CreatedUtc"]="$(get_octopusvariable "Octopus.Deployment.CreatedUtc")"

Copy link
Contributor

@benPearce1 benPearce1 Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backtick characters also need to be escaped.

image image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up raising an issue
OctopusDeploy/Issues#9255

@@ -44,6 +45,9 @@ public static string PrepareConfigurationFile(string workingDirectory, IVariable
var encryptedVariables = EncryptVariables(variables);
builder.Replace("#### VariableDeclarations ####", string.Join(LinuxNewLine, GetVariableSwitchConditions(encryptedVariables)));

builder.Replace("#### BashParametersArrayFeatureToggle ####", FeatureToggle.BashParametersArrayFeatureToggle.IsEnabled(variables) ? "true" : "false");
builder.Replace("#### VariableNamesArrayDeclarations ####", FeatureToggle.BashParametersArrayFeatureToggle.IsEnabled(variables) ? string.Join(" ", GetVariableNameAndValueDeclaration(encryptedVariables)) : string.Empty);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only replace the variableNamesArrayDecleration if the feature toggle is enabled. This prevents any malformed variables from breaking the bash script if the toggle is disabled.

{
return variables.Select(variable =>
{
var variableValue = $@"$(get_octopusvariable ""{variable.Name.Replace("\"", "\\\"")}"")";
Copy link
Contributor Author

@IsaacCalligeros95 IsaacCalligeros95 Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm calling get_octopusvariable to avoid passing through the encrypted variables etc a second time. Generally this should involve less characters in the final bash script but the generated command is large. I still need to do some performance testing on this but it's instant on a local project with minimal variables.

if [ "$bashParametersArrayFeatureToggle" = true ]; then
    if (( ${BASH_VERSINFO[0]} > 4 || (${BASH_VERSINFO[0]} == 4 && ${BASH_VERSINFO[1]} > 2) )); then
      declare -grA octopus_parameters=(["Octopus.Agent.ProgramDirectoryPath"]="$(get_octopusvariable "Octopus.Agent.ProgramDirectoryPath")" ["Octopus.Sashimi.ScriptFunctions.Registration"]="$(get_octopusvariable "Octopus.Sashimi.ScriptFunctions.Registration")" ["Octopus.Deployment.Id"]="$(get_octopusvariable "Octopus.Deployment.Id")" ["Octopus.Deployment.Name"]="$(get_octopusvariable "Octopus.Deployment.Name")" ["Octopus.Deployment.Created"]="$(get_octopusvariable "Octopus.Deployment.Created")" ["Octopus.Deployment.CreatedUtc"]="$(get_octopusvariable "Octopus.Deployment.CreatedUtc")" ["Octopus.Deployment.Comments"]="$(get_octopusvariable "Octopus.Deployment.Comments")" ["Octopus.Deployment.ForcePackageDownload"]="$(get_octopusvariable "Octopus.Deployment.ForcePackageDownload")" ["Octopus.Deployment.SpecificMachines"]="$(get_octopusvariable "Octopus.Deployment.SpecificMachines")" ["Octopus.Deployment.ExcludedMachines"]="$(get_octopusvariable "Octopus.Deployment.ExcludedMachines")" ["Octopus.Project.Id"]="$(get_octopusvariable "Octopus.Project.Id")" ["Octopus.Project.Name"]="$(get_octopusvariable "Octopus.Project.Name")" ["Octopus.Project.Slug"]="$(get_octopusvariable "Octopus.Project.Slug")" ["Octopus.ProjectGroup.Id"]="$(get_octopusvariable "Octopus.ProjectGroup.Id")" ["Octopus.ProjectGroup.Name"]="$(get_octopusvariable "Octopus.ProjectGroup.Name")" ["Octopus.Environment.Id"]="$(get_octopusvariable "Octopus.Environment.Id")" ["Octopus.Environment.Name"]="$(get_octopusvariable "Octopus.Environment.Name")" ["Octopus.Environment.SortOrder"]="$(get_octopusvariable "Octopus.Environment.SortOrder")" ["Octopus.Release.Id"]="$(get_octopusvariable "Octopus.Release.Id")" ["Octopus.Release.Number"]="$(get_octopusvariable "Octopus.Release.Number")" ["Octopus.Release.Created"]="$(get_octopusvariable "Octopus.Release.Created")" ["Octopus.Release.CreatedUtc"]="$(get_octopusvariable "Octopus.Release.CreatedUtc")" ["Octopus.Release.Notes"]="$(get_octopusvariable "Octopus.Release.Notes")" ["Octopus.Task.Id"]="$(get_octopusvariable "Octopus.Task.Id")" ["Octopus.Task.Name"]="$(get_octopusvariable "Octopus.Task.Name")" ["Octopus.Task.QueueTime"]="$(get_octopusvariable "Octopus.Task.QueueTime")" ["Octopus.Task.QueueTimeExpiry"]="$(get_octopusvariable "Octopus.Task.QueueTimeExpiry")" ["Octopus.Task.Argument[DeploymentId]"]="$(get_octopusvariable "Octopus.Task.Argument[DeploymentId]")" ["Octopus.Release.Channel.Id"]="$(get_octopusvariable "Octopus.Release.Channel.Id")" ["Octopus.Release.Channel.Name"]="$(get_octopusvariable "Octopus.Release.Channel.Name")" ["Octopus.Space.Id"]="$(get_octopusvariable "Octopus.Space.Id")" ["Octopus.Space.Name"]="$(get_octopusvariable "Octopus.Space.Name")" ["Octopus.Web.BaseUrl"]="$(get_octopusvariable "Octopus.Web.BaseUrl")" ["Octopus.Web.ServerUri"]="$(get_octopusvariable "Octopus.Web.ServerUri")" ["Octopus.Web.DeploymentLink"]="$(get_octopusvariable "Octopus.Web.DeploymentLink")" ["Octopus.Web.ReleaseLink"]="$(get_octopusvariable "Octopus.Web.ReleaseLink")" ["Octopus.Web.ProjectLink"]="$(get_octopusvariable "Octopus.Web.ProjectLink")" ["Octopus.Action.Number"]="$(get_octopusvariable "Octopus.Action.Number")" ["Octopus.Action.StepName"]="$(get_octopusvariable "Octopus.Action.StepName")" ["Octopus.Step.Number"]="$(get_octopusvariable "Octopus.Step.Number")" ["Octopus.Step.Id"]="$(get_octopusvariable "Octopus.Step.Id")" ["Octopus.Step.Name"]="$(get_octopusvariable "Octopus.Step.Name")" ["Octopus.Action.TargetRoles"]="$(get_octopusvariable "Octopus.Action.TargetRoles")" ["Octopus.Action.Id"]="$(get_octopusvariable "Octopus.Action.Id")" ["Octopus.Action.Name"]="$(get_octopusvariable "Octopus.Action.Name")" ["OctopusUseBundledTooling"]="$(get_octopusvariable "OctopusUseBundledTooling")" ["Octopus.Action.RunOnServer"]="$(get_octopusvariable "Octopus.Action.RunOnServer")" ["Octopus.Action.Script.ScriptSource"]="$(get_octopusvariable "Octopus.Action.Script.ScriptSource")" ["Octopus.Action.Script.Syntax"]="$(get_octopusvariable "Octopus.Action.Script.Syntax")" ["Octopus.Action.Script.ScriptBody"]="$(get_octopusvariable "Octopus.Action.Script.ScriptBody")" ["Octopus.Action.Container.Image"]="$(get_octopusvariable "Octopus.Action.Container.Image")" ["Octopus.Action.Container.Feed"]="$(get_octopusvariable "Octopus.Action.Container.Feed")" ["Octopus.Action.Container.GitUrl"]="$(get_octopusvariable "Octopus.Action.Container.GitUrl")" ["Octopus.Action.Container.Dockerfile"]="$(get_octopusvariable "Octopus.Action.Container.Dockerfile")" ["Octopus.Step[Run a Script].Number"]="$(get_octopusvariable "Octopus.Step[Run a Script].Number")" ["Octopus.Step[Run a Script].Id"]="$(get_octopusvariable "Octopus.Step[Run a Script].Id")" ["Octopus.Step[Run a Script].Name"]="$(get_octopusvariable "Octopus.Step[Run a Script].Name")" ["Octopus.Deployment.CreatedBy.Id"]="$(get_octopusvariable "Octopus.Deployment.CreatedBy.Id")" ["Octopus.Deployment.CreatedBy.Username"]="$(get_octopusvariable "Octopus.Deployment.CreatedBy.Username")" ["Octopus.Deployment.CreatedBy.DisplayName"]="$(get_octopusvariable "Octopus.Deployment.CreatedBy.DisplayName")" ["Octopus.Deployment.CreatedBy.EmailAddress"]="$(get_octopusvariable "Octopus.Deployment.CreatedBy.EmailAddress")" ["Octopus.Tentacle.CurrentDeployment.RetentionPolicySubset"]="$(get_octopusvariable "Octopus.Tentacle.CurrentDeployment.RetentionPolicySubset")" ["OctopusRetentionPolicySet"]="$(get_octopusvariable "OctopusRetentionPolicySet")" ["OctopusRetentionPolicyItemsToKeep"]="$(get_octopusvariable "OctopusRetentionPolicyItemsToKeep")" ["OctopusUseGuidedFailure"]="$(get_octopusvariable "OctopusUseGuidedFailure")" ["Secrety!"]="$(get_octopusvariable "Secrety!")" ["test 'hello'"]="$(get_octopusvariable "test 'hello'")" ["key.2"]="$(get_octopusvariable "key.2")" ["Octopus.Calamari.Executable"]="$(get_octopusvariable "Octopus.Calamari.Executable")" ["Single"quote"]="$(get_octopusvariable "Single"quote")" ["t't"]="$(get_octopusvariable "t't")" ["Octopus.Calamari.CopyWorkingDirectoryIncludingKeyTo"]="$(get_octopusvariable "Octopus.Calamari.CopyWorkingDirectoryIncludingKeyTo")" ["Octopus.Release.Previous.Id"]="$(get_octopusvariable "Octopus.Release.Previous.Id")" ["Octopus.Release.Previous.Number"]="$(get_octopusvariable "Octopus.Release.Previous.Number")" ["Octopus.Release.PreviousForEnvironment.Id"]="$(get_octopusvariable "Octopus.Release.PreviousForEnvironment.Id")" ["Octopus.Release.PreviousForEnvironment.Number"]="$(get_octopusvariable "Octopus.Release.PreviousForEnvironment.Number")" ["Octopus.Release.CurrentForEnvironment.Id"]="$(get_octopusvariable "Octopus.Release.CurrentForEnvironment.Id")" ["Octopus.Release.CurrentForEnvironment.Number"]="$(get_octopusvariable "Octopus.Release.CurrentForEnvironment.Number")" ["Octopus.Deployment.PreviousSuccessful.Id"]="$(get_octopusvariable "Octopus.Deployment.PreviousSuccessful.Id")" ["Octopus.Calamari.ArchiveLimits.Enabled"]="$(get_octopusvariable "Octopus.Calamari.ArchiveLimits.Enabled")" ["Octopus.Calamari.ArchiveLimits.Metrics.Enabled"]="$(get_octopusvariable "Octopus.Calamari.ArchiveLimits.Metrics.Enabled")" ["Octopus.Calamari.ArchiveLimits.MaximumCompressionRatio"]="$(get_octopusvariable "Octopus.Calamari.ArchiveLimits.MaximumCompressionRatio")" ["Octopus.Calamari.ArchiveLimits.MaximumUncompressedSize"]="$(get_octopusvariable "Octopus.Calamari.ArchiveLimits.MaximumUncompressedSize")" ["Octopus.Deployment.WorkItems"]="$(get_octopusvariable "Octopus.Deployment.WorkItems")" ["Octopus.Deployment.PackageBuildInformation"]="$(get_octopusvariable "Octopus.Deployment.PackageBuildInformation")" ["Octopus.Deployment.PackageBuildMetadata"]="$(get_octopusvariable "Octopus.Deployment.PackageBuildMetadata")" ["Octopus.Deployment.Changes"]="$(get_octopusvariable "Octopus.Deployment.Changes")" ["OctopusEnabledFeatureToggles"]="$(get_octopusvariable "OctopusEnabledFeatureToggles")" ["Octopus.Deployment.ChangesMarkdown"]="$(get_octopusvariable "Octopus.Deployment.ChangesMarkdown")" ["Octopus.Deployment.Machines"]="$(get_octopusvariable "Octopus.Deployment.Machines")" ["Octopus.Environment.MachinesInRole[isaacwel]"]="$(get_octopusvariable "Octopus.Environment.MachinesInRole[isaacwel]")" ["Octopus.Machine.Id"]="$(get_octopusvariable "Octopus.Machine.Id")" ["Octopus.Machine.Name"]="$(get_octopusvariable "Octopus.Machine.Name")" ["Octopus.Tentacle.Agent.ApplicationDirectoryPath"]="$(get_octopusvariable "Octopus.Tentacle.Agent.ApplicationDirectoryPath")" ["Octopus.Tentacle.Agent.InstanceName"]="$(get_octopusvariable "Octopus.Tentacle.Agent.InstanceName")" ["Octopus.Tentacle.Agent.ProgramDirectoryPath"]="$(get_octopusvariable "Octopus.Tentacle.Agent.ProgramDirectoryPath")" ["Octopus.Machine.CommunicationStyle"]="$(get_octopusvariable "Octopus.Machine.CommunicationStyle")" ["Octopus.Machine.DeploymentTargetType"]="$(get_octopusvariable "Octopus.Machine.DeploymentTargetType")" ["Octopus.Machine.Hostname"]="$(get_octopusvariable "Octopus.Machine.Hostname")" ["Octopus.Machine.Roles"]="$(get_octopusvariable "Octopus.Machine.Roles")" ["Octopus.Machine.Tags"]="$(get_octopusvariable "Octopus.Machine.Tags")" ["Octopus.Machine.TenantIds"]="$(get_octopusvariable "Octopus.Machine.TenantIds")" ["Octopus.Step[Run a Script].Status.Code"]="$(get_octopusvariable "Octopus.Step[Run a Script].Status.Code")" ["Octopus.Action[Run a Script].Output.Octopus.Action.ExecutionContext.Location"]="$(get_octopusvariable "Octopus.Action[Run a Script].Output.Octopus.Action.ExecutionContext.Location")" ["Octopus.Action[Run a Script].Output.Octopus.Action.ExecutionContext.WorkerId"]="$(get_octopusvariable "Octopus.Action[Run a Script].Output.Octopus.Action.ExecutionContext.WorkerId")" ["Octopus.Action[Run a Script].Output.Octopus.Action.ExecutionContext.IsDynamicWorker"]="$(get_octopusvariable "Octopus.Action[Run a Script].Output.Octopus.Action.ExecutionContext.IsDynamicWorker")" ["Octopus.Action[Run a Script].Number"]="$(get_octopusvariable "Octopus.Action[Run a Script].Number")" ["Octopus.Action[Run a Script].StepName"]="$(get_octopusvariable "Octopus.Action[Run a Script].StepName")" ["Octopus.Action[Run a Script].TargetRoles"]="$(get_octopusvariable "Octopus.Action[Run a Script].TargetRoles")" ["Octopus.Action[Run a Script].Id"]="$(get_octopusvariable "Octopus.Action[Run a Script].Id")" ["Octopus.Action[Run a Script].Name"]="$(get_octopusvariable "Octopus.Action[Run a Script].Name")" ["Octopus.Action[Run a Script].RunOnServer"]="$(get_octopusvariable "Octopus.Action[Run a Script].RunOnServer")" ["Octopus.Action[Run a Script].Script.ScriptSource"]="$(get_octopusvariable "Octopus.Action[Run a Script].Script.ScriptSource")" ["Octopus.Action[Run a Script].Script.Syntax"]="$(get_octopusvariable "Octopus.Action[Run a Script].Script.Syntax")" ["Octopus.Action[Run a Script].Script.ScriptBody"]="$(get_octopusvariable "Octopus.Action[Run a Script].Script.ScriptBody")" ["Octopus.Action[Run a Script].Container.Image"]="$(get_octopusvariable "Octopus.Action[Run a Script].Container.Image")" ["Octopus.Action[Run a Script].Container.Feed"]="$(get_octopusvariable "Octopus.Action[Run a Script].Container.Feed")" ["Octopus.Action[Run a Script].Container.GitUrl"]="$(get_octopusvariable "Octopus.Action[Run a Script].Container.GitUrl")" ["Octopus.Action[Run a Script].Container.Dockerfile"]="$(get_octopusvariable "Octopus.Action[Run a Script].Container.Dockerfile")" ["Octopus.Action[Run a Script].Output[isaac wsl].Octopus.Action.ExecutionContext.Location"]="$(get_octopusvariable "Octopus.Action[Run a Script].Output[isaac wsl].Octopus.Action.ExecutionContext.Location")" ["Octopus.Action[Run a Script].Output[isaac wsl].Octopus.Action.ExecutionContext.WorkerId"]="$(get_octopusvariable "Octopus.Action[Run a Script].Output[isaac wsl].Octopus.Action.ExecutionContext.WorkerId")" ["Octopus.Action[Run a Script].Output[isaac wsl].Octopus.Action.ExecutionContext.IsDynamicWorker"]="$(get_octopusvariable "Octopus.Action[Run a Script].Output[isaac wsl].Octopus.Action.ExecutionContext.IsDynamicWorker")" ["Octopus.Action[Run a Script].AutoRetry.CurrentCount"]="$(get_octopusvariable "Octopus.Action[Run a Script].AutoRetry.CurrentCount")" ["Octopus.Tentacle.CurrentDeployment.TargetedRoles"]="$(get_octopusvariable "Octopus.Tentacle.CurrentDeployment.TargetedRoles")" ["Octopus.Action.Script.CSharp.UseOctopusClassBootstrapper"]="$(get_octopusvariable "Octopus.Action.Script.CSharp.UseOctopusClassBootstrapper")" ["Octopus.Action.Script.CSharp.UseDotnetScript"]="$(get_octopusvariable "Octopus.Action.Script.CSharp.UseDotnetScript")" ["env:LICENSE"]="$(get_octopusvariable "env:LICENSE")" ["env:COMPUTERNAME"]="$(get_octopusvariable "env:COMPUTERNAME")" ["env:PROCESSOR_LEVEL"]="$(get_octopusvariable "env:PROCESSOR_LEVEL")" ["env:USERDOMAIN"]="$(get_octopusvariable "env:USERDOMAIN")" ["env:TEAMCITY_AGENT_OPTS"]="$(get_octopusvariable "env:TEAMCITY_AGENT_OPTS")" ["env:PROCESSOR_REVISION"]="$(get_octopusvariable "env:PROCESSOR_REVISION")" ["env:octopus_api_key"]="$(get_octopusvariable "env:octopus_api_key")" ["env:OneDriveConsumer"]="$(get_octopusvariable "env:OneDriveConsumer")" ["env:Azure_OctopusAPITester_ClientId"]="$(get_octopusvariable "env:Azure_OctopusAPITester_ClientId")" ["env:Google_Map_ApiKey_NotSecret"]="$(get_octopusvariable "env:Google_Map_ApiKey_NotSecret")" ["env:AWS_SECRET_ACCESS_KEY"]="$(get_octopusvariable "env:AWS_SECRET_ACCESS_KEY")" ["env:PATHEXT"]="$(get_octopusvariable "env:PATHEXT")" ["env:SQL_IntegrationTest_Pooling"]="$(get_octopusvariable "env:SQL_IntegrationTest_Pooling")" ["env:Nautilus_Ca_Cert"]="$(get_octopusvariable "env:Nautilus_Ca_Cert")" ["env:GitHub_OctopusAPITester_Password"]="$(get_octopusvariable "env:GitHub_OctopusAPITester_Password")" ["env:TeamCity_OctopusAPITester_AccessToken"]="$(get_octopusvariable "env:TeamCity_OctopusAPITester_AccessToken")" ["env:ChocolateyLastPathUpdate"]="$(get_octopusvariable "env:ChocolateyLastPathUpdate")" ["env:K8S_OctopusAPITester_Server"]="$(get_octopusvariable "env:K8S_OctopusAPITester_Server")" ["env:HOMEPATH"]="$(get_octopusvariable "env:HOMEPATH")" ["env:ALLUSERSPROFILE"]="$(get_octopusvariable "env:ALLUSERSPROFILE")" ["env:PROCESSOR_ARCHITECTURE"]="$(get_octopusvariable "env:PROCESSOR_ARCHITECTURE")" ["env:VAULT_ADDR"]="$(get_octopusvariable "env:VAULT_ADDR")" ["env:ProgramData"]="$(get_octopusvariable "env:ProgramData")" ["env:WSLENV"]="$(get_octopusvariable "env:WSLENV")" ["env:LOGONSERVER"]="$(get_octopusvariable "env:LOGONSERVER")" ["env:SQL_IntegrationTest_Password"]="$(get_octopusvariable "env:SQL_IntegrationTest_Password")" ["env:ProgramFiles(x86)"]="$(get_octopusvariable "env:ProgramFiles(x86)")" ["env:JAVA_HOME"]="$(get_octopusvariable "env:JAVA_HOME")" ["env:NUMBER_OF_PROCESSORS"]="$(get_octopusvariable "env:NUMBER_OF_PROCESSORS")" ["env:Octopus_E2E_Tests_SSH_Targets_Service_Account_Token"]="$(get_octopusvariable "env:Octopus_E2E_Tests_SSH_Targets_Service_Account_Token")" ["env:OPENSSL_CONF"]="$(get_octopusvariable "env:OPENSSL_CONF")" ["env:NVM_HOME"]="$(get_octopusvariable "env:NVM_HOME")" ["env:WT_SESSION"]="$(get_octopusvariable "env:WT_SESSION")" ["env:K8S_OctopusAPITester_Username"]="$(get_octopusvariable "env:K8S_OctopusAPITester_Username")" ["env:OctopusCalamariWorkingDirectory"]="$(get_octopusvariable "env:OctopusCalamariWorkingDirectory")" ["env:Octopus_E2E_Local_Testing_Service_Account_Token"]="$(get_octopusvariable "env:Octopus_E2E_Local_Testing_Service_Account_Token")" ["env:OCTOPUS_UNLIMITED_LICENSE"]="$(get_octopusvariable "env:OCTOPUS_UNLIMITED_LICENSE")" ["env:ComSpec"]="$(get_octopusvariable "env:ComSpec")" ["env:K8S_OctopusAPITester_Password"]="$(get_octopusvariable "env:K8S_OctopusAPITester_Password")" ["env:MyLocalPassword"]="$(get_octopusvariable "env:MyLocalPassword")" ["env:USERDOMAIN_ROAMINGPROFILE"]="$(get_octopusvariable "env:USERDOMAIN_ROAMINGPROFILE")" ["env:CommonProgramW6432"]="$(get_octopusvariable "env:CommonProgramW6432")" ["env:TF_ACC"]="$(get_octopusvariable "env:TF_ACC")" ["env:MyTestVariable"]="$(get_octopusvariable "env:MyTestVariable")" ["env:TF_ACC_LOCAL"]="$(get_octopusvariable "env:TF_ACC_LOCAL")" ["env:Azure_OctopusAPITester_Password"]="$(get_octopusvariable "env:Azure_OctopusAPITester_Password")" ["env:LOCALAPPDATA"]="$(get_octopusvariable "env:LOCALAPPDATA")" ["env:octopusURL"]="$(get_octopusvariable "env:octopusURL")" ["env:PUBLIC"]="$(get_octopusvariable "env:PUBLIC")" ["env:SystemDrive"]="$(get_octopusvariable "env:SystemDrive")" ["env:Nautilus_Api_Address_Prod"]="$(get_octopusvariable "env:Nautilus_Api_Address_Prod")" ["env:ProgramFiles"]="$(get_octopusvariable "env:ProgramFiles")" ["env:GRADLE_HOME"]="$(get_octopusvariable "env:GRADLE_HOME")" ["env:ZES_ENABLE_SYSMAN"]="$(get_octopusvariable "env:ZES_ENABLE_SYSMAN")" ["env:ProgramW6432"]="$(get_octopusvariable "env:ProgramW6432")" ["env:Azure_OctopusAPITester_TenantId"]="$(get_octopusvariable "env:Azure_OctopusAPITester_TenantId")" ["env:KUBECONFIG"]="$(get_octopusvariable "env:KUBECONFIG")" ["env:TF_LOG"]="$(get_octopusvariable "env:TF_LOG")" ["env:NVM_SYMLINK"]="$(get_octopusvariable "env:NVM_SYMLINK")" ["env:TEAMCITY_SERVER_OPTS"]="$(get_octopusvariable "env:TEAMCITY_SERVER_OPTS")" ["env:SESSIONNAME"]="$(get_octopusvariable "env:SESSIONNAME")" ["env:AZURE_SUBSCRIPTION_ID"]="$(get_octopusvariable "env:AZURE_SUBSCRIPTION_ID")" ["env:POWERSHELL_DISTRIBUTION_CHANNEL"]="$(get_octopusvariable "env:POWERSHELL_DISTRIBUTION_CHANNEL")" ["env:WIX"]="$(get_octopusvariable "env:WIX")" ["env:AZURE_TENANT_ID"]="$(get_octopusvariable "env:AZURE_TENANT_ID")" ["env:Google_Places_API_Key"]="$(get_octopusvariable "env:Google_Places_API_Key")" ["env:VAULT_TOKEN"]="$(get_octopusvariable "env:VAULT_TOKEN")" ["env:AWS_ACCESS_KEY_ID"]="$(get_octopusvariable "env:AWS_ACCESS_KEY_ID")" ["env:Path"]="$(get_octopusvariable "env:Path")" ["env:TMP"]="$(get_octopusvariable "env:TMP")" ["env:VAULT_NAMESPACE"]="$(get_octopusvariable "env:VAULT_NAMESPACE")" ["env:SQL_IntegrationTest_Username"]="$(get_octopusvariable "env:SQL_IntegrationTest_Username")" ["env:K8S_OctopusAPITester_Token"]="$(get_octopusvariable "env:K8S_OctopusAPITester_Token")" ["env:OCTOPUS_URL"]="$(get_octopusvariable "env:OCTOPUS_URL")" ["env:AWS_E2E_SecretKeyId"]="$(get_octopusvariable "env:AWS_E2E_SecretKeyId")" ["env:GOPATH"]="$(get_octopusvariable "env:GOPATH")" ["env:Octopus.Action.Script.CSharp.UseDotnetScript"]="$(get_octopusvariable "env:Octopus.Action.Script.CSharp.UseDotnetScript")" ["env:USERPROFILE"]="$(get_octopusvariable "env:USERPROFILE")" ["env:AWS_OctopusAPITester_Access"]="$(get_octopusvariable "env:AWS_OctopusAPITester_Access")" ["env:OneDrive"]="$(get_octopusvariable "env:OneDrive")" ["env:WT_PROFILE_ID"]="$(get_octopusvariable "env:WT_PROFILE_ID")" ["env:AWS_OctopusAPITester_Secret"]="$(get_octopusvariable "env:AWS_OctopusAPITester_Secret")" ["env:AZURE_CLIENT_PASSWORD"]="$(get_octopusvariable "env:AZURE_CLIENT_PASSWORD")" ["env:ChocolateyToolsLocation"]="$(get_octopusvariable "env:ChocolateyToolsLocation")" ["env:HOMEDRIVE"]="$(get_octopusvariable "env:HOMEDRIVE")" ["env:SystemRoot"]="$(get_octopusvariable "env:SystemRoot")" ["env:AWS_E2E_AccessKeyId"]="$(get_octopusvariable "env:AWS_E2E_AccessKeyId")" ["env:APPDATA"]="$(get_octopusvariable "env:APPDATA")" ["env:PROCESSOR_IDENTIFIER"]="$(get_octopusvariable "env:PROCESSOR_IDENTIFIER")" ["env:PNPM_HOME"]="$(get_octopusvariable "env:PNPM_HOME")" ["env:DriverData"]="$(get_octopusvariable "env:DriverData")" ["env:windir"]="$(get_octopusvariable "env:windir")" ["env:PSModulePath"]="$(get_octopusvariable "env:PSModulePath")" ["env:AZURE_CLIENT_ID"]="$(get_octopusvariable "env:AZURE_CLIENT_ID")" ["env:OS"]="$(get_octopusvariable "env:OS")" ["env:Azure_OctopusAPITester_SubscriptionId"]="$(get_octopusvariable "env:Azure_OctopusAPITester_SubscriptionId")" ["env:OCTODISABLEOCTOCONTAINERLOGGING"]="$(get_octopusvariable "env:OCTODISABLEOCTOCONTAINERLOGGING")" ["env:azure_client_secret"]="$(get_octopusvariable "env:azure_client_secret")" ["env:OCTOPUS_APIKEY"]="$(get_octopusvariable "env:OCTOPUS_APIKEY")" ["env:TEMP"]="$(get_octopusvariable "env:TEMP")" ["env:GitHub_OctopusAPITester_Username"]="$(get_octopusvariable "env:GitHub_OctopusAPITester_Username")" ["env:USERNAME"]="$(get_octopusvariable "env:USERNAME")" ["env:CommonProgramFiles"]="$(get_octopusvariable "env:CommonProgramFiles")" ["env:SQL_IntegrationTest_Instance"]="$(get_octopusvariable "env:SQL_IntegrationTest_Instance")" ["env:CommonProgramFiles(x86)"]="$(get_octopusvariable "env:CommonProgramFiles(x86)")" ["Octopus.Tentacle.PreviousInstallation.OriginalInstalledPath"]="$(get_octopusvariable "Octopus.Tentacle.PreviousInstallation.OriginalInstalledPath")" ["Octopus.Tentacle.PreviousInstallation.CustomInstallationDirectory"]="$(get_octopusvariable "Octopus.Tentacle.PreviousInstallation.CustomInstallationDirectory")" ["Octopus.Tentacle.PreviousInstallation.PackageFilePath"]="$(get_octopusvariable "Octopus.Tentacle.PreviousInstallation.PackageFilePath")" ["Octopus.Tentacle.PreviousInstallation.PackageVersion"]="$(get_octopusvariable "Octopus.Tentacle.PreviousInstallation.PackageVersion")" ["Octopus.Tentacle.PreviousSuccessfulInstallation.OriginalInstalledPath"]="$(get_octopusvariable "Octopus.Tentacle.PreviousSuccessfulInstallation.OriginalInstalledPath")" ["Octopus.Tentacle.PreviousSuccessfulInstallation.CustomInstallationDirectory"]="$(get_octopusvariable "Octopus.Tentacle.PreviousSuccessfulInstallation.CustomInstallationDirectory")" ["Octopus.Tentacle.PreviousSuccessfulInstallation.PackageFilePath"]="$(get_octopusvariable "Octopus.Tentacle.PreviousSuccessfulInstallation.PackageFilePath")" ["Octopus.Tentacle.PreviousSuccessfulInstallation.PackageVersion"]="$(get_octopusvariable "Octopus.Tentacle.PreviousSuccessfulInstallation.PackageVersion")" ["Octopus.Action.Script.ScriptFileName"]="$(get_octopusvariable "Octopus.Action.Script.ScriptFileName")")
    else
      echo "Bash version 4.2 or later is required to use octopus_parameters"
    fi
fi

Copy link
Contributor

@benPearce1 benPearce1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to cater for the backtick scenario

@IsaacCalligeros95 IsaacCalligeros95 force-pushed the isaac/bash-variable-iteration branch from d03fc3a to a42951e Compare February 20, 2025 00:01
}

hex_to_string() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use xxd this can be removed. xxd is generally included with vim and should be available on most Linux machines but is not generally available on Mac.

@IsaacCalligeros95 IsaacCalligeros95 force-pushed the isaac/bash-variable-iteration branch from ea2d016 to aa2fc9e Compare February 20, 2025 00:16
if [ "$bashParametersArrayFeatureToggle" = true ]; then
if (( ${BASH_VERSINFO[0]:-0} > 4 || (${BASH_VERSINFO[0]:-0} == 4 && ${BASH_VERSINFO[1]:-0} > 2) )); then
if command -v xxd > /dev/null; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to use xxd, but if we don't the implementation is very messy and I had to write the hex string to disk for performance issues (It was being cleaned up immediately after). Implementation on this commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants