通过Nuke.Common/NuGet.CommandLine部署NuGet软件包时如何通过Azure Auth [英] How to pass Azure Auth when Deploying NuGet Package via Nuke.Common/NuGet.CommandLine

查看:56
本文介绍了通过Nuke.Common/NuGet.CommandLine部署NuGet软件包时如何通过Azure Auth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Azure DevOps上的Nuke和CI/CD自动执行NuGet软件包更新.一切工作都很好,但是在PushNuGet步骤中,该过程尝试通过弹出窗口向Azure进行身份验证,该窗口显然从未呈现过[在devops中]或未回答

I'm attempting to automate NuGet Package updates through Nuke and CI/CD on Azure DevOps. Everything is building just fine, but during the PushNuGet step, the process tries to authenticate with Azure via a pop-up window, which is obviously never rendered [in devops] or answered

class Build : NukeBuild
{
    /// Support plugins are available for:
    ///   - JetBrains ReSharper        https://nuke.build/resharper
    ///   - JetBrains Rider            https://nuke.build/rider
    ///   - Microsoft VisualStudio     https://nuke.build/visualstudio
    ///   - Microsoft VSCode           https://nuke.build/vscode

    public static int Main () => Execute<Build>(x => x.PushNuGet);

    [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
    readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;

    [Solution] readonly Solution Solution;
    [GitRepository] readonly GitRepository GitRepository;

    AbsolutePath SourceDirectory => RootDirectory / "src";
    AbsolutePath TestsDirectory => RootDirectory / "tests";
    AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";

    string VersionNumber = "1.0.2";

    Target Clean => _ => _
        .Executes(() =>
        {
            SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
            TestsDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
            EnsureCleanDirectory(ArtifactsDirectory);
        });

    Target Restore => _ => _
        .DependsOn(Clean)
        .Executes(() =>
        {
            DotNetRestore(s => s
                .SetProjectFile(Solution));
        });

    Target Compile => _ => _
        .DependsOn(Restore)
        .Executes(() =>
        {
            DotNetBuild(s => s
                .SetProjectFile(Solution)
                .SetConfiguration(Configuration)
                .EnableNoRestore());
        });

    Target Pack => _ => _
        .DependsOn(Compile)
        .Executes(() =>
        {
            DotNetPack(s => s
                .SetProject(RootDirectory + "\\Fuze.Models\\Fuze.Models.csproj")
                .SetNoBuild(true)
                .SetConfiguration(Configuration)    
                .SetVersion(VersionNumber)
            );
        });

    Target AddSource => _ => _
       .DependsOn(Pack)
       .Executes(() =>
       {
            var sourceUrl = "https://pkgs.dev.azure.com/DataFuzionHCM/_packaging/DataFuzionHCM/nuget/v3/index.json";
            var sourceName = "DataFuzionHCM";
            var sources = NuGetTasks.NuGetSourcesList();
            if(sources.Any(source => source.Text.Contains(sourceName)))
            {
               NuGetTasks.NuGetSourcesRemove(s => s.SetName(sourceName));
            }
            NuGetTasks.NuGetSourcesAdd(s => s
                .SetName(sourceName)
                .SetSource(sourceUrl)
                .SetUserName("NuGet Feed Token")
                .SetPassword("fakepassword")
            );
       });

    Target PushNuGet => _ => _
        .DependsOn(AddSource)
        .Executes(() =>
        {
            NuGetTasks.NuGetPush(s => s
                .SetSource("DataFuzionHCM")
                .SetApiKey("az")
                .SetTargetPath(RootDirectory + $"/FUZE.Models/bin/debug/Fuze.Models.{VersionNumber}.nupkg")
            );
        });
}

在Azure生成管道上,在最后一步中,可以在作业日志中看到它被天青卡在某个身份验证窗口中.

On the Azure Build Pipeline, During the last step, it can be seen in the job log that it's getting stuck on some auth window with azure.

Using credentials from config. UserName: NuGet Feed Token
    [CredentialProvider]Using the ADAL UI  flow for uri https://pkgs.dev.[hidden]ure.com/DataFuzionHCM/_packaging/DataFuzionHCM/nuget/v3/index.json. User sign-in required in a pop-up authentication window.
    [CredentialProvider]Using the ADAL UI  flow for uri https://pkgs.dev.[hidden]ure.com/DataFuzionHCM/_packaging/DataFuzionHCM/nuget/v3/index.json. User sign-in required in a pop-up authentication window.
    [CredentialProvider]Using the ADAL UI  flow for uri https://pkgs.dev.[hidden]ure.com/DataFuzionHCM/_packaging/DataFuzionHCM/nuget/v3/index.json. User sign-in required in a pop-up authentication window.
##[error]Unable to load the service index for source https://pkgs.dev.[hidden]ure.com/DataFuzionHCM/_packaging/DataFuzionHCM/nuget/v3/index.json.
##[error]  The HTTP request to 'GET https://pkgs.dev.[hidden]ure.com/DataFuzionHCM/_packaging/DataFuzionHCM/nuget/v3/index.json' has timed out after 100000ms.
##[error]Process 'NuGet.exe' exited with code 1.

是否存在一种通过Azure进行编程身份验证的方法,以使其不会在popup-auth处挂起并超时?

Is there a method to programmatically authenticate with Azure so it doesn't hang and timeout at the popup-auth?

推荐答案

事实证明,NuGet提要的密码已过期,因此,当身份验证失败时,它会提示您进行身份验证,而不是抛出身份验证错误.我进入DevOps并更新了密码的到期日期,然后一切正常.

It turns out that the password for the NuGet feed was expired, so when auth failed, it prompted for auth instead of throwing an auth error. I went into DevOps and updated the expiration date on the password and, from there, everything worked fine.

我确实感到奇怪,它没有抛出auth错误,而是在单独的窗口上从本地用户要求输入密码.在设计用于更新NuGet软件包的API时,也许没有考虑自动化.

I do find it odd that instead of throwing an auth error, it instead asks for a password from the local user on a separate window. Perhaps automation wasn't something that was taken into account when the API's for updating NuGet packages were designed.

这篇关于通过Nuke.Common/NuGet.CommandLine部署NuGet软件包时如何通过Azure Auth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆