Skip to content

Commit 4c81851

Browse files
author
JoshuaMiller
committed
package on ci build; publish using deploy
1 parent fa3d269 commit 4c81851

4 files changed

Lines changed: 87 additions & 63 deletions

File tree

Jenkins.NET.Publishing/Jenkins.NET.Publishing.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@
9696
<Reference Include="WindowsBase" />
9797
</ItemGroup>
9898
<ItemGroup>
99-
<Compile Include="Scripts\Publish.cs" />
100-
<Compile Include="Scripts\Build.cs" />
99+
<Compile Include="Scripts\Package.cs" />
101100
<Compile Include="Properties\AssemblyInfo.cs" />
101+
<Compile Include="Scripts\Publish.cs" />
102102
<Compile Include="Tools\BuildTools.cs" />
103103
<Compile Include="Tools\TestTools.cs" />
104104
</ItemGroup>

Jenkins.Net.Publishing/Scripts/Build.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using Jenkins.NET.Publishing.Tools;
2+
using Photon.Framework.Agent;
3+
using Photon.Framework.Packages;
4+
using Photon.Framework.Process;
5+
using Photon.Framework.Tasks;
6+
using System;
7+
using System.IO;
8+
using System.Threading;
9+
using System.Threading.Tasks;
10+
11+
namespace Jenkins.NET.Publishing.Scripts
12+
{
13+
public class Package : IBuildTask
14+
{
15+
public IAgentBuildContext Context {get; set;}
16+
17+
18+
public async Task RunAsync(CancellationToken token)
19+
{
20+
var packageDir = Path.Combine(Context.WorkDirectory, "Packages");
21+
22+
await BuildTools.BuildSolution(Context, token);
23+
await TestTools.UnitTest(Context, token);
24+
25+
await CreateNugetPackage(packageDir, token);
26+
27+
await CreateProjectPackage(packageDir, token);
28+
}
29+
30+
private async Task CreateProjectPackage(string packageDir, CancellationToken token)
31+
{
32+
var def = new ProjectPackageDefinition {
33+
Id = "jenkinsnet",
34+
Name = "Jenkins.NET",
35+
Description = "Publishes a pre-compiled and pre-tested NuGet Package for Jenkins.NET.",
36+
Project = "jenkins.net",
37+
Assembly = "Jenkins.Net.Publishing.dll",
38+
Script = "Publish",
39+
Files = {
40+
new PackageFileDefinition {
41+
Path = packageDir,
42+
Destination = "",
43+
}
44+
}
45+
};
46+
47+
var version = Context.BuildNumber.ToString();
48+
var output = Path.Combine(Context.BinDirectory, "Jenkins.Net.zip");
49+
50+
await ProjectPackageTools.CreatePackage(
51+
definition: def,
52+
rootPath: Context.ContentDirectory,
53+
version: version,
54+
outputFilename: output);
55+
56+
await Context.Packages.PushProjectPackageAsync(output, token);
57+
}
58+
59+
private async Task CreateNugetPackage(string packageDir, CancellationToken token)
60+
{
61+
var args = new[] {
62+
"pack",
63+
"\"Jenkins.Net\\Jenkins.Net.csproj\"",
64+
"--configuration Release",
65+
"--no-build",
66+
$"--output \"{packageDir}\"",
67+
};
68+
69+
var info = new ProcessRunInfo {
70+
Filename = "dotnet",
71+
Arguments = string.Join(" ", args),
72+
WorkingDirectory = Context.ContentDirectory,
73+
};
74+
75+
var runner = new ProcessRunner(Context);
76+
var result = await runner.RunAsync(info, token);
77+
78+
if (result.ExitCode != 0) throw new ApplicationException($"Build Failed! [{result.ExitCode}]");
79+
}
80+
}
81+
}
Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using Jenkins.NET.Publishing.Tools;
2-
using Photon.Framework.Agent;
3-
using Photon.Framework.Process;
4-
using Photon.Framework.Tasks;
1+
using Photon.Framework.Server;
52
using Photon.NuGet.CorePlugin;
63
using System;
74
using System.IO;
@@ -11,11 +8,11 @@
118

129
namespace Jenkins.NET.Publishing.Scripts
1310
{
14-
public class Publish : IBuildTask
11+
internal class Publish : IDeployScript
1512
{
1613
private NuGetCore nugetCore;
1714

18-
public IAgentBuildContext Context {get; set;}
15+
public IServerDeployContext Context {get; set;}
1916

2017

2118
public async Task RunAsync(CancellationToken token)
@@ -25,48 +22,14 @@ public async Task RunAsync(CancellationToken token)
2522
};
2623
nugetCore.Initialize();
2724

28-
await BuildTools.BuildSolution(Context, token);
29-
await TestTools.UnitTest(Context, token);
30-
31-
await PublishPackage(token);
32-
}
33-
34-
private async Task PublishPackage(CancellationToken token)
35-
{
36-
var packageDir = Path.Combine(Context.WorkDirectory, "Packages");
37-
38-
await Pack(packageDir, token);
39-
4025
var packageFilename = Directory
41-
.GetFiles(packageDir, "jenkinsnet.*.nupkg")
26+
.GetFiles(Context.ContentDirectory, "jenkinsnet.*.nupkg")
4227
.FirstOrDefault();
4328

4429
if (string.IsNullOrEmpty(packageFilename))
4530
throw new ApplicationException("No package found matching package ID 'jenkinsnet'!");
4631

4732
await nugetCore.PushAsync(packageFilename, token);
4833
}
49-
50-
private async Task Pack(string packageDir, CancellationToken token)
51-
{
52-
var args = new[] {
53-
"pack",
54-
"\"Jenkins.Net\\Jenkins.Net.csproj\"",
55-
"--configuration Release",
56-
"--no-build",
57-
$"--output \"{packageDir}\"",
58-
};
59-
60-
var info = new ProcessRunInfo {
61-
Filename = "dotnet",
62-
Arguments = string.Join(" ", args),
63-
WorkingDirectory = Context.ContentDirectory,
64-
};
65-
66-
var runner = new ProcessRunner(Context);
67-
var result = await runner.RunAsync(info, token);
68-
69-
if (result.ExitCode != 0) throw new ApplicationException($"Build Failed! [{result.ExitCode}]");
70-
}
7134
}
7235
}

0 commit comments

Comments
 (0)