-
Notifications
You must be signed in to change notification settings - Fork 112
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
b2a8fc0
0f18b78
42c821c
603c18f
3f24cd0
4ee6131
0cb6b29
a811021
798130f
c6c4156
ad7439d
a42951e
aa2fc9e
7172ba1
fd8ed23
c1c3c90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
using System.Text; | ||
using Calamari.Common.Features.Processes; | ||
using Calamari.Common.Features.Scripts; | ||
using Calamari.Common.FeatureToggles; | ||
using Calamari.Common.Plumbing; | ||
using Calamari.Common.Plumbing.Extensions; | ||
using Calamari.Common.Plumbing.FileSystem; | ||
|
@@ -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); | ||
|
||
using (var file = new FileStream(configurationFile, FileMode.CreateNew, FileAccess.Write)) | ||
using (var writer = new StreamWriter(file, Encoding.ASCII)) | ||
{ | ||
|
@@ -55,6 +59,15 @@ public static string PrepareConfigurationFile(string workingDirectory, IVariable | |
return configurationFile; | ||
} | ||
|
||
static IEnumerable<string> GetVariableNameAndValueDeclaration(IEnumerable<EncryptedVariable> variables) | ||
{ | ||
return variables.Select(variable => | ||
{ | ||
var variableValue = $@"$(get_octopusvariable ""{variable.Name.Replace("\"", "\\\"")}"")"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our intellisense insert-variable function is broken for a variable with a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ended up raising an issue There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
|
||
return $"[\"{variable.Name.Replace("\"", "\\\"")}\"]=\"{variableValue}\""; | ||
}); | ||
} | ||
|
||
static IList<EncryptedVariable> EncryptVariables(IVariables variables) | ||
{ | ||
return variables.GetNames() | ||
|
There was a problem hiding this comment.
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.