nuke-build / nuke

🏗 The AKEless Build System for C#/.NET
https://nuke.build
MIT License
3.07k stars 367 forks source link

Azure Pipelines: AccessToken not available #1352

Closed coding-red-panda closed 8 months ago

coding-red-panda commented 8 months ago

Usage Information

8.0.0

Description

Hello,

I'm following the documentation to configure the access token for our private NuGet Feed. So I have created a Target as follows:

[AzurePipelines(
    null,
    AzurePipelinesImage.UbuntuLatest,
    InvokedTargets = new[] { nameof(AzureCiBuild) },
    EnableAccessToken = true,
    ImportVariableGroups = new[] { "dotnet-global-variables" },
    AutoGenerate = false)]
class Build : NukeBuild
{
Target EnsurePrivateNuGetFeedToken => x => x
        .OnlyWhenStatic(() => Host is AzurePipelines)
        .Before(Restore)
        .Executes(() =>
        {
            if (string.IsNullOrWhiteSpace(AzurePipelines.Instance.AccessToken))
            {
                Assert.Fail("Azure DevOps NuGet feed token is not set");
            }

            try
            {
                Log.Information("Setting NuGet source {Feed} API key...",NuGetFeed);
                DotNetTasks.DotNetNuGetAddSource(c => c
                    .SetName("Development")
                    .SetSource(NuGetFeed)
                    .SetUsername("AzureDevOps")
                    .SetPassword(AzurePipelines.Instance.AccessToken)
                    // Password encryption is not supported by Azure DevOps
                    .SetStorePasswordInClearText(true)
                    // Need to set arguments manually as serialization using `SetValidAuthenticationTypes` is broken
                    .SetProcessArgumentConfigurator(arguments =>
                        arguments.Add("--valid-authentication-types basic,negotiate")));
            }
            catch
            {
                Log.Warning("Source already exists, skipping...");
            }
        });
}

And this is constantly failing on the CI because the assert is getting triggered. So the AzurePipelines.Instance.AccessToken always returns null or an empty string for us.

Reproduction Steps

Expected Behavior

The token should be available for the pipeline

Actual Behavior

No token is loaded

Regression?

No idea, first time trying Nuke. Only other issue I found was the enabling for the flag.

Known Workarounds

No response

Could you help with a pull-request?

No

matkoch commented 8 months ago

yaml file regenerated? how does it look?

coding-red-panda commented 8 months ago

yaml file regenerated? how does it look?

Sorry, I don't understand the question. What YAML file should be regenerated?

matkoch commented 8 months ago

if you don't understand my question, maybe you should read the docs page once more :) i'd just repeat myself here

coding-red-panda commented 8 months ago

Build runs fine locally, and no changes detected in the pipeline yaml. We've had the EnableAccessToken set to true prior to adding this new task we just never used it before but are switching to it now as we want to expose a package.

All Targets themselves work fine locally, just on the Azure CI the token property is not being populated.