mirror of
https://github.com/actions/runner.git
synced 2025-12-12 05:37:01 +00:00
Thechrisjohnson/runnerregistration (#623)
* Add ability to register a runner to the non-default self-hosted runner group (#613) Co-authored-by: Christopher Johnson <thchrisjohnson@github.com> * Ship 2.267.2 runner Co-authored-by: Christopher Johnson <thchrisjohnson@github.com>
This commit is contained in:
committed by
GitHub
parent
fd3c9de49d
commit
deccb261d3
@@ -1,6 +1,7 @@
|
|||||||
## Features
|
## Features
|
||||||
- Resolve action download info from server (#508, #515, #550)
|
- Resolve action download info from server (#508, #515, #550)
|
||||||
- Print runner and machine name to log. (#539)
|
- Print runner and machine name to log. (#539)
|
||||||
|
- Allow runner to register against non-default runner groups (#517)
|
||||||
## Bugs
|
## Bugs
|
||||||
- Reduce input validation warnings (#506)
|
- Reduce input validation warnings (#506)
|
||||||
- Fix null ref exception in SecretMasker caused by `hashfiles` timeout. (#516)
|
- Fix null ref exception in SecretMasker caused by `hashfiles` timeout. (#516)
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
2.267.1
|
2.267.2
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ namespace GitHub.Runner.Common
|
|||||||
public static readonly string Labels = "labels";
|
public static readonly string Labels = "labels";
|
||||||
public static readonly string MonitorSocketAddress = "monitorsocketaddress";
|
public static readonly string MonitorSocketAddress = "monitorsocketaddress";
|
||||||
public static readonly string Name = "name";
|
public static readonly string Name = "name";
|
||||||
public static readonly string Pool = "pool";
|
public static readonly string RunnerGroup = "runnergroup";
|
||||||
public static readonly string StartupType = "startuptype";
|
public static readonly string StartupType = "startuptype";
|
||||||
public static readonly string Url = "url";
|
public static readonly string Url = "url";
|
||||||
public static readonly string UserName = "username";
|
public static readonly string UserName = "username";
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace GitHub.Runner.Listener
|
|||||||
Constants.Runner.CommandLine.Args.Labels,
|
Constants.Runner.CommandLine.Args.Labels,
|
||||||
Constants.Runner.CommandLine.Args.MonitorSocketAddress,
|
Constants.Runner.CommandLine.Args.MonitorSocketAddress,
|
||||||
Constants.Runner.CommandLine.Args.Name,
|
Constants.Runner.CommandLine.Args.Name,
|
||||||
Constants.Runner.CommandLine.Args.Pool,
|
Constants.Runner.CommandLine.Args.RunnerGroup,
|
||||||
Constants.Runner.CommandLine.Args.StartupType,
|
Constants.Runner.CommandLine.Args.StartupType,
|
||||||
Constants.Runner.CommandLine.Args.Token,
|
Constants.Runner.CommandLine.Args.Token,
|
||||||
Constants.Runner.CommandLine.Args.Url,
|
Constants.Runner.CommandLine.Args.Url,
|
||||||
@@ -169,6 +169,15 @@ namespace GitHub.Runner.Listener
|
|||||||
validator: Validators.NonEmptyValidator);
|
validator: Validators.NonEmptyValidator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetRunnerGroupName(string defaultPoolName = null)
|
||||||
|
{
|
||||||
|
return GetArgOrPrompt(
|
||||||
|
name: Constants.Runner.CommandLine.Args.RunnerGroup,
|
||||||
|
description: "Enter the name of the runner group to add this runner to:",
|
||||||
|
defaultValue: defaultPoolName ?? "default",
|
||||||
|
validator: Validators.NonEmptyValidator);
|
||||||
|
}
|
||||||
|
|
||||||
public string GetToken()
|
public string GetToken()
|
||||||
{
|
{
|
||||||
return GetArgOrPrompt(
|
return GetArgOrPrompt(
|
||||||
|
|||||||
@@ -159,17 +159,34 @@ namespace GitHub.Runner.Listener.Configuration
|
|||||||
|
|
||||||
_term.WriteSection("Runner Registration");
|
_term.WriteSection("Runner Registration");
|
||||||
|
|
||||||
//Get all the agent pools, and select the first private pool
|
// If we have more than one runner group available, allow the user to specify which one to be added into
|
||||||
|
string poolName = null;
|
||||||
|
TaskAgentPool agentPool = null;
|
||||||
List<TaskAgentPool> agentPools = await _runnerServer.GetAgentPoolsAsync();
|
List<TaskAgentPool> agentPools = await _runnerServer.GetAgentPoolsAsync();
|
||||||
TaskAgentPool agentPool = agentPools?.Where(x => x.IsHosted == false).FirstOrDefault();
|
TaskAgentPool defaultPool = agentPools?.Where(x => x.IsInternal).FirstOrDefault();
|
||||||
|
|
||||||
if (agentPool == null)
|
if (agentPools?.Where(x => !x.IsHosted).Count() > 1)
|
||||||
{
|
{
|
||||||
throw new TaskAgentPoolNotFoundException($"Could not find any private pool. Contact support.");
|
poolName = command.GetRunnerGroupName(defaultPool?.Name);
|
||||||
|
_term.WriteLine();
|
||||||
|
agentPool = agentPools.Where(x => string.Equals(poolName, x.Name, StringComparison.OrdinalIgnoreCase) && !x.IsHosted).FirstOrDefault();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Trace.Info("Found a private pool with id {1} and name {2}", agentPool.Id, agentPool.Name);
|
agentPool = defaultPool;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (agentPool == null && poolName == null)
|
||||||
|
{
|
||||||
|
throw new TaskAgentPoolNotFoundException($"Could not find any self-hosted runner groups. Contact support.");
|
||||||
|
}
|
||||||
|
else if (agentPool == null && poolName != null)
|
||||||
|
{
|
||||||
|
throw new TaskAgentPoolNotFoundException($"Could not find any self-hosted runner group named \"{poolName}\".");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Trace.Info("Found a self-hosted runner group with id {1} and name {2}", agentPool.Id, agentPool.Name);
|
||||||
runnerSettings.PoolId = agentPool.Id;
|
runnerSettings.PoolId = agentPool.Id;
|
||||||
runnerSettings.PoolName = agentPool.Name;
|
runnerSettings.PoolName = agentPool.Name;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ namespace GitHub.DistributedTask.WebApi
|
|||||||
this.PoolType = referenceToBeCloned.PoolType;
|
this.PoolType = referenceToBeCloned.PoolType;
|
||||||
this.Size = referenceToBeCloned.Size;
|
this.Size = referenceToBeCloned.Size;
|
||||||
this.IsLegacy = referenceToBeCloned.IsLegacy;
|
this.IsLegacy = referenceToBeCloned.IsLegacy;
|
||||||
|
this.IsInternal = referenceToBeCloned.IsInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskAgentPoolReference Clone()
|
public TaskAgentPoolReference Clone()
|
||||||
@@ -67,6 +68,16 @@ namespace GitHub.DistributedTask.WebApi
|
|||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether or not this pool is internal and can't be modified by users
|
||||||
|
/// </summary>
|
||||||
|
[DataMember]
|
||||||
|
public bool IsInternal
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the type of the pool
|
/// Gets or sets the type of the pool
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -39,10 +39,12 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration
|
|||||||
private string _expectedToken = "expectedToken";
|
private string _expectedToken = "expectedToken";
|
||||||
private string _expectedServerUrl = "https://codedev.ms";
|
private string _expectedServerUrl = "https://codedev.ms";
|
||||||
private string _expectedAgentName = "expectedAgentName";
|
private string _expectedAgentName = "expectedAgentName";
|
||||||
private string _expectedPoolName = "poolName";
|
private string _defaultRunnerGroupName = "defaultRunnerGroup";
|
||||||
|
private string _secondRunnerGroupName = "secondRunnerGroup";
|
||||||
private string _expectedAuthType = "pat";
|
private string _expectedAuthType = "pat";
|
||||||
private string _expectedWorkFolder = "_work";
|
private string _expectedWorkFolder = "_work";
|
||||||
private int _expectedPoolId = 1;
|
private int _defaultRunnerGroupId = 1;
|
||||||
|
private int _secondRunnerGroupId = 2;
|
||||||
private RSACryptoServiceProvider rsa = null;
|
private RSACryptoServiceProvider rsa = null;
|
||||||
private RunnerSettings _configMgrAgentSettings = new RunnerSettings();
|
private RunnerSettings _configMgrAgentSettings = new RunnerSettings();
|
||||||
|
|
||||||
@@ -97,7 +99,7 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration
|
|||||||
_serviceControlManager.Setup(x => x.GenerateScripts(It.IsAny<RunnerSettings>()));
|
_serviceControlManager.Setup(x => x.GenerateScripts(It.IsAny<RunnerSettings>()));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
var expectedPools = new List<TaskAgentPool>() { new TaskAgentPool(_expectedPoolName) { Id = _expectedPoolId } };
|
var expectedPools = new List<TaskAgentPool>() { new TaskAgentPool(_defaultRunnerGroupName) { Id = _defaultRunnerGroupId, IsInternal = true }, new TaskAgentPool(_secondRunnerGroupName) { Id = _secondRunnerGroupId } };
|
||||||
_runnerServer.Setup(x => x.GetAgentPoolsAsync(It.IsAny<string>(), It.IsAny<TaskAgentPoolType>())).Returns(Task.FromResult(expectedPools));
|
_runnerServer.Setup(x => x.GetAgentPoolsAsync(It.IsAny<string>(), It.IsAny<TaskAgentPoolType>())).Returns(Task.FromResult(expectedPools));
|
||||||
|
|
||||||
var expectedAgents = new List<TaskAgent>();
|
var expectedAgents = new List<TaskAgent>();
|
||||||
@@ -155,7 +157,7 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration
|
|||||||
"configure",
|
"configure",
|
||||||
"--url", _expectedServerUrl,
|
"--url", _expectedServerUrl,
|
||||||
"--name", _expectedAgentName,
|
"--name", _expectedAgentName,
|
||||||
"--pool", _expectedPoolName,
|
"--runnergroup", _secondRunnerGroupName,
|
||||||
"--work", _expectedWorkFolder,
|
"--work", _expectedWorkFolder,
|
||||||
"--auth", _expectedAuthType,
|
"--auth", _expectedAuthType,
|
||||||
"--token", _expectedToken,
|
"--token", _expectedToken,
|
||||||
@@ -175,7 +177,7 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration
|
|||||||
Assert.NotNull(s);
|
Assert.NotNull(s);
|
||||||
Assert.True(s.ServerUrl.Equals(_expectedServerUrl));
|
Assert.True(s.ServerUrl.Equals(_expectedServerUrl));
|
||||||
Assert.True(s.AgentName.Equals(_expectedAgentName));
|
Assert.True(s.AgentName.Equals(_expectedAgentName));
|
||||||
Assert.True(s.PoolId.Equals(_expectedPoolId));
|
Assert.True(s.PoolId.Equals(_secondRunnerGroupId));
|
||||||
Assert.True(s.WorkFolder.Equals(_expectedWorkFolder));
|
Assert.True(s.WorkFolder.Equals(_expectedWorkFolder));
|
||||||
|
|
||||||
// validate GetAgentPoolsAsync gets called twice with automation pool type
|
// validate GetAgentPoolsAsync gets called twice with automation pool type
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
2.267.1
|
2.267.2
|
||||||
|
|||||||
Reference in New Issue
Block a user