From 48a94cb1aa78ad33adfe47e3d8d3bd4e49dbdbf0 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Fri, 28 Jan 2022 07:29:44 +0100 Subject: [PATCH] Fix NuGet publish credentials --- .gitlab-ci.yml | 2 +- .nuke/build.schema.json | 8 -------- build/Build.cs | 15 +++------------ 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3474751..6f10418 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -58,4 +58,4 @@ nuget-publish: - tags script: - dotnet tool restore - - dotnet nuke NuGetPush --nuget-username "${NUGET_USERNAME}" --nuget-password "${NUGET_PASSWORD}" + - dotnet nuke NuGetPush diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index ed1030d..1828fb1 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -46,14 +46,6 @@ "type": "boolean", "description": "Disables displaying the NUKE logo" }, - "nuget-password": { - "type": "string", - "description": "Password to use for publishing NuGet packages" - }, - "nuget-username": { - "type": "string", - "description": "Username to use for publishing NuGet packages" - }, "Partition": { "type": "string", "description": "Partition to use on CI" diff --git a/build/Build.cs b/build/Build.cs index f559c63..c691524 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -1,5 +1,3 @@ -using System; -using JetBrains.Annotations; using NuGet.Versioning; using Nuke.Common; using Nuke.Common.CI; @@ -25,12 +23,6 @@ class Build : NukeBuild [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; - [Parameter("Username to use for publishing NuGet packages", Name = "nuget-username")] - string NuGetUsername { get; set; } = Environment.GetEnvironmentVariable("NUGET_USERNAME") ?? string.Empty; - - [Parameter("Password to use for publishing NuGet packages", Name = "nuget-password")] - string NuGetPassword { get; set; } = Environment.GetEnvironmentVariable("NUGET_PASSWORD") ?? string.Empty; - [Solution] readonly Solution? Solution; [GitRepository] readonly GitRepository? GitRepository; [GitVersion(NoFetch = true, Framework = "net6.0")] readonly GitVersion? GitVersion; @@ -107,14 +99,13 @@ class Build : NukeBuild ))); Target AddNugetSource => _ => _ - .OnlyWhenStatic(() => CI != null && !string.IsNullOrEmpty(CI.CommitTag)) - .OnlyWhenStatic(() => !string.IsNullOrEmpty(NuGetUsername) && !string.IsNullOrEmpty(NuGetPassword)) + .OnlyWhenStatic(() => CI != null && !string.IsNullOrEmpty(CI.CommitTag) && !string.IsNullOrEmpty(CI.JobToken)) .ProceedAfterFailure() .Executes(() => DotNetNuGetAddSource(s => s .SetName(NuGetSourceName) .SetSource($"https://gitlab.com/api/v4/projects/{CI?.ProjectId}/packages/nuget/index.json") - .SetUsername(NuGetUsername) - .SetPassword(NuGetPassword) + .SetUsername("gitlab-ci-token") + .SetPassword(CI!.JobToken) .EnableStorePasswordInClearText())); Target NuGetPush => _ => _