cake-build / cake-build/cake

Automatic argument retrieval with fallback mechanism

Open
#1,265 7 comments 0 reactions 0 assignees View on GitHub
Good first issue Help wanted Improvement Up-for-grabs
Dominant language
C#
Stars
4.2k
Forks
778
Avg merge
1h 15m
Merged PRs (30d)
19

Description

For my own purposes I have created this convenience method. It checks for argument values in the following order:
1. Specified via command line
2. Specified via build server (build server variable)
3. Specified via environment variable

This way we need less explicit variable definitions because most of them are automatically retrieved from the build server (in most cases, people are running cake from a build server and pass in variables already defined in the build server).

It's currently written for continua ci only, but this can easily be extended to other build servers as well and renamed to GetVariable

```
public string GetContinuaCIVariable(string variableName, string defaultValue)
{
var argumentValue = Argument(variableName, "non-existing");
if (argumentValue != "non-existing")
{
Information("Variable '{0}' is specified via an argument", variableName);

return argumentValue;
}

if (ContinuaCI.IsRunningOnContinuaCI)
{
var buildServerVariables = ContinuaCI.Environment.Variable;
if (buildServerVariables.ContainsKey(variableName))
{
Information("Variable '{0}' is specified via Continua CI", variableName);

return buildServerVariables[variableName];
}
}

if (HasEnvironmentVariable(variableName))
{
Information("Variable '{0}' is specified via an environment variable", variableName);

return EnvironmentVariable(variableName);
}

Information("Variable '{0}' is not specified, returning default value", variableName);

return defaultValue;
}
```

What do you think, is it worth PR-ing?

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the existing Argument, ContinuaCI, HasEnvironmentVariable, and EnvironmentVariable entry points shown in the issue. Determine whether the fallback should remain Continua CI-specific or become a broader GetVariable API, and establish the supported precedence and default behavior. Done means the scope is agreed and the behavior is covered for the supported sources.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system, ci-cd, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.