Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions Tasks/DotNetCoreCLIV2/Tests/PushTests/skipDuplicate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import ma = require('azure-pipelines-task-lib/mock-answer');
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');
import util = require('../DotnetMockHelper');

let taskPath = path.join(__dirname, '../..', 'dotnetcore.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
let nmh: util.DotnetMockHelper = new util.DotnetMockHelper(tmr);
nmh.setNugetVersionInputDefault();
tmr.setInput('command', 'push');
tmr.setInput('searchPatternPush', 'foo.nupkg');
tmr.setInput('nuGetFeedType', 'internal');
tmr.setInput('feedPublish', 'ProjectId/FeedFooId');
tmr.setInput('arguments', '--skip-duplicate');

let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"osType": {},
"checkPath": {
"c:\\agent\\home\\directory\\foo.nupkg": true,
"c:\\path\\dotnet.exe": true
},
"which": {
"dotnet": "c:\\path\\dotnet.exe"
},
"exec": {
// First push succeeds
"c:\\path\\dotnet.exe nuget push c:\\agent\\home\\directory\\foo.nupkg --source https://vsts/packagesource --api-key VSTS": {
"code": 0,
"stdout": "dotnet output",
"stderr": ""
},
// Second push (duplicate) also succeeds due to --skip-duplicate
"c:\\path\\dotnet.exe nuget push c:\\agent\\home\\directory\\foo.nupkg --source https://vsts/packagesource --api-key VSTS --skip-duplicate": {
"code": 0,
"stdout": "Package already exists, skipping due to --skip-duplicate",
"stderr": ""
}
},
"exist": {},
"stats": {
"c:\\agent\\home\\directory\\foo.nupkg": {
"isFile": true
}
},
"rmRF": {
"c:\\agent\\home\\directory\\NuGet_1": {
"success": true
}
},
"findMatch": {
"fromMockedUtility-foo.nupkg": ["c:\\agent\\home\\directory\\foo.nupkg"]
}
};
nmh.setAnswers(a);
nmh.registerNugetUtilityMock(["c:\\agent\\home\\directory\\foo.nupkg"]);
nmh.registerDefaultNugetVersionMock();
nmh.registerToolRunnerMock();
nmh.registerNugetConfigMock();
nmh.RegisterLocationServiceMocks();

// Simulate pushing the same package twice
tmr.run();
tmr.run();
4 changes: 2 additions & 2 deletions Tasks/DotNetCoreCLIV2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Tasks/DotNetCoreCLIV2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vsts-tasks-dotnetcoreexe",
"version": "2.129.4",
"version": "2.258.0",
"description": "Dotnet core exe",
"main": "dotnetcore.js",
"scripts": {
Expand Down
10 changes: 7 additions & 3 deletions Tasks/DotNetCoreCLIV2/pushcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export async function run(): Promise<void> {
tl.debug(`all URL prefixes: ${urlPrefixes}`);
}

// Read arguments so users can specify extra arguments like --skip-duplicate
let dotnetArguments: string = tl.getInput('arguments', false) || '';

// Setting up auth info
let accessToken;
const isInternalFeed: boolean = nugetFeedType === 'internal';
Expand Down Expand Up @@ -164,14 +167,13 @@ export async function run(): Promise<void> {
const dotnetPath = tl.which('dotnet', true);
try {
for (const packageFile of filesList) {
await dotNetNuGetPushAsync(dotnetPath, packageFile, feedUri, apiKey, configFile, tempNuGetConfigDirectory);
await dotNetNuGetPushAsync(dotnetPath, packageFile, feedUri, apiKey, dotnetArguments, configFile, tempNuGetConfigDirectory);
}
} finally {
credCleanup();
}

tl.setResult(tl.TaskResult.Succeeded, tl.loc('PackagesPublishedSuccessfully'));

} catch (err) {
tl.error(err);

Expand All @@ -183,7 +185,7 @@ export async function run(): Promise<void> {
}
}

function dotNetNuGetPushAsync(dotnetPath: string, packageFile: string, feedUri: string, apiKey: string, configFile: string, workingDirectory: string): Q.Promise<number> {
function dotNetNuGetPushAsync(dotnetPath: string, packageFile: string, feedUri: string, apiKey: string, dotnetArguments: string, configFile: string, workingDirectory: string): Q.Promise<number> {
const dotnet = tl.tool(dotnetPath);

dotnet.arg('nuget');
Expand All @@ -197,6 +199,8 @@ function dotNetNuGetPushAsync(dotnetPath: string, packageFile: string, feedUri:
dotnet.arg('--api-key');
dotnet.arg(apiKey);

dotnet.line(dotnetArguments);

// dotnet.exe v1 and v2 do not accept the --verbosity parameter for the "nuget push"" command, although it does for other commands
const envWithProxy = ngRunner.setNuGetProxyEnvironment(process.env, /*configFile*/ null, feedUri);
return dotnet.exec({ cwd: workingDirectory, env: envWithProxy } as IExecOptions);
Expand Down