Hi @jimbobmcgee,
This restriction is for security purposes, specifically to enable the usecase of Otter enabling end-users to create/edit/run scripts, but not decide where they are run. So the for server
is locked unless the targeting is set to None.
The solution is to indeed add a variable that allows you to select a server... but as you noticed, you'd have to type in a list. We simply ran out of time to bring those over from BuildMaster unfortunately, and this is not really a popular Otter requirement.
But sure it's possible, it's called a VariableTemplateType
. Here is the code from BuildMaster that you could probably copy/paste into a custom extension.
But the issue is that you don't have access to DB
in the SDK. Kind of a pain, but you could either reference Otter.Core.dll in your Nuget Package, use reflection, call DB directrly, etc.
[Category("Infrastructure")]
[DisplayName("Servers")]
[Description("Servers configured in BuildMaster, optionally filtered by one or more environments")]
public sealed class ServerListVariableSource : BuildMasterDynamicListVariableType
{
[Persistent]
[DisplayName("Environment filter")]
[PlaceholderText("Any environment")]
[Inedo.Web.SuggestableValue(typeof(EnvironmentNameSuggestionProvider))]
public string EnvironmentsFilter { get; set; }
private class EnvironmentNameSuggestionProvider : ISuggestionProvider
{
public async Task<IEnumerable<string>> GetSuggestionsAsync(IComponentConfiguration config) =>
(await DB
.Environments_GetEnvironmentsAsync().ConfigureAwait(false))
.Select(e => e.Environment_Name);
}
public async override Task<IEnumerable<string>> EnumerateListValuesAsync(VariableTemplateContext context)
{
var values = (await DB.Environments_GetEnvironmentsAndServersAsync(false).ConfigureAwait(false))
.EnvironmentServers_Extended
.Where(es => es.Server_Active_Indicator)
.Where(es => string.IsNullOrEmpty(this.EnvironmentsFilter) || string.Equals(this.EnvironmentsFilter, es.Environment_Name, StringComparison.OrdinalIgnoreCase))
.Select(es => es.Server_Name)
.Distinct();
return values;
}
public override RichDescription GetDescription()
{
if (this.EnvironmentsFilter?.Length > 0)
return new RichDescription("Servers in ", new ListHilite(this.EnvironmentsFilter), " environments.");
else
return new RichDescription("Servers in all environments.");
}
}
It is on our list to "Make Job Template Varible Editor Closer to Pipeline Variable Editor", it's just not trivial and not a huge priority on our products roadmap (https://inedo.com/products/roadmap)
Cheers,
Alana