Compare commits

...

2 Commits

Author SHA1 Message Date
Christopher Schleiden
6141233980 Use different url format for accessing API 2020-03-27 10:32:15 -07:00
TingluoHuang
5e670caa0b add _IS_GITHUB to overwrite URL switch. 2020-03-26 22:31:25 -04:00

View File

@@ -93,9 +93,11 @@ namespace GitHub.Runner.Listener.Configuration
while (true) while (true)
{ {
// Get the URL // Get the URL
var isGitHub = StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable("_IS_GITHUB"));
var inputUrl = command.GetUrl(); var inputUrl = command.GetUrl();
if (!inputUrl.Contains("github.com", StringComparison.OrdinalIgnoreCase) && if (!inputUrl.Contains("github.com", StringComparison.OrdinalIgnoreCase) &&
!inputUrl.Contains("github.localhost", StringComparison.OrdinalIgnoreCase)) !inputUrl.Contains("github.localhost", StringComparison.OrdinalIgnoreCase) &&
!isGitHub)
{ {
runnerSettings.ServerUrl = inputUrl; runnerSettings.ServerUrl = inputUrl;
// Get the credentials // Get the credentials
@@ -198,7 +200,7 @@ namespace GitHub.Runner.Listener.Configuration
} }
else else
{ {
// Create a new agent. // Create a new agent.
agent = CreateNewAgent(runnerSettings.AgentName, publicKey); agent = CreateNewAgent(runnerSettings.AgentName, publicKey);
try try
@@ -290,7 +292,7 @@ namespace GitHub.Runner.Listener.Configuration
{ {
// there are two exception messages server send that indicate clock skew. // there are two exception messages server send that indicate clock skew.
// 1. The bearer token expired on {jwt.ValidTo}. Current server time is {DateTime.UtcNow}. // 1. The bearer token expired on {jwt.ValidTo}. Current server time is {DateTime.UtcNow}.
// 2. The bearer token is not valid until {jwt.ValidFrom}. Current server time is {DateTime.UtcNow}. // 2. The bearer token is not valid until {jwt.ValidFrom}. Current server time is {DateTime.UtcNow}.
Trace.Error("Catch exception during test agent connection."); Trace.Error("Catch exception during test agent connection.");
Trace.Error(ex); Trace.Error(ex);
throw new Exception("The local machine's clock may be out of sync with the server time by more than five minutes. Please sync your clock with your domain or internet time and try again."); throw new Exception("The local machine's clock may be out of sync with the server time by more than five minutes. Please sync your clock with your domain or internet time and try again.");
@@ -402,7 +404,7 @@ namespace GitHub.Runner.Listener.Configuration
_term.WriteLine("Cannot connect to server, because config files are missing. Skipping removing runner from the server."); _term.WriteLine("Cannot connect to server, because config files are missing. Skipping removing runner from the server.");
} }
//delete credential config files //delete credential config files
currentAction = "Removing .credentials"; currentAction = "Removing .credentials";
if (hasCredentials) if (hasCredentials)
{ {
@@ -416,7 +418,7 @@ namespace GitHub.Runner.Listener.Configuration
_term.WriteLine("Does not exist. Skipping " + currentAction); _term.WriteLine("Does not exist. Skipping " + currentAction);
} }
//delete settings config file //delete settings config file
currentAction = "Removing .runner"; currentAction = "Removing .runner";
if (isConfigured) if (isConfigured)
{ {
@@ -520,7 +522,7 @@ namespace GitHub.Runner.Listener.Configuration
private async Task<GitHubAuthResult> GetTenantCredential(string githubUrl, string githubToken, string runnerEvent) private async Task<GitHubAuthResult> GetTenantCredential(string githubUrl, string githubToken, string runnerEvent)
{ {
var gitHubUrlBuilder = new UriBuilder(githubUrl); var gitHubUrlBuilder = new UriBuilder(githubUrl);
var githubApiUrl = $"{gitHubUrlBuilder.Scheme}://api.{gitHubUrlBuilder.Host}/actions/runner-registration"; var githubApiUrl = $"{gitHubUrlBuilder.Scheme}://{gitHubUrlBuilder.Host}/api/v3/actions/runner-registration";
using (var httpClientHandler = HostContext.CreateHttpClientHandler()) using (var httpClientHandler = HostContext.CreateHttpClientHandler())
using (var httpClient = new HttpClient(httpClientHandler)) using (var httpClient = new HttpClient(httpClientHandler))
{ {