diff --git a/api/git/azure.go b/api/git/azure.go index 5f08036d9..3b0686722 100644 --- a/api/git/azure.go +++ b/api/git/azure.go @@ -253,18 +253,19 @@ func parseHttpUrl(rawUrl string) (*azureOptions, error) { return nil, errors.Wrap(err, "failed to parse HTTP url") } azureDevOpsServerURL, azureDevOpsServerURLOK := os.LookupEnv("AZURE_DEVOPS_SERVER_URL") + var azureDevOpsServerParsedURL *url.URL if azureDevOpsServerURLOK { - azureDevOpsServerParsedURL, err := url.Parse(rawUrl) + azureDevOpsServerParsedURL, err = url.Parse(azureDevOpsServerURL) if err != nil { return nil, errors.Wrap(err, "failed to parse Azure DevOps Server url") } } opt := azureOptions{} switch { - case azureDevOpsServerURLOK && u.Host == azureDevOpsServerParsedURL.host: - path = strings.Split(strings.ReplaceAll(u.Path, azureDevOpsServerParsedURL.path, ""), "/") + case azureDevOpsServerURLOK && azureDevOpsServerParsedURL != nil && u.Host == azureDevOpsServerParsedURL.Host: + path := strings.Split(strings.ReplaceAll(u.Path, azureDevOpsServerParsedURL.Path, ""), "/") if len(path) != 5 { - expectedUrl = azureDevOpsServerURL + "/{Collection}/{Project}/_git/{Repository}" + expectedUrl := azureDevOpsServerURL + "/{Collection}/{Project}/_git/{Repository}" return nil, errors.Errorf("want url %s, got %s", expectedUrl, u) } opt.organisation = path[1] //In case of AzureDevops Server Organisation is replaced with Collection but their logic is the same