Skip to content

Commit

Permalink
#6 Adding slack integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Phi Huynh committed Apr 20, 2017
1 parent cb3e724 commit ef02e86
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 0 deletions.
91 changes: 91 additions & 0 deletions templates/aspnetcore/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
properties([gitLabConnection('Gitlab')])

pipeline {
agent any
stages {
stage('notifyStarted') {
steps {
notifyStarted()
}
}
stage('Build') {
steps {
sh '''
if [ "$(docker ps -aq -f name=aspnetcore)" ]; then
docker rm -f aspnetcore
fi
if [ "$(docker ps -aq -f name=aspnetcore-uat)" ]; then
docker rm -f aspnetcore-uat
fi
if [ "$(docker ps -aq -f name=aspnetcore-prod)" ]; then
docker rm -f aspnetcore-prod
fi
'''
sh '''cd src
dotnet restore
dotnet build
dotnet publish -c Release -o /artifacts'''
}
}
stage('Tests') {
steps {
parallel(
"Unit Tests": {
sh 'cd tests && dotnet restore && dotnet test --logger "trx;LogFileName=abc.trx"'

},
"Integration Tests": {
sh 'echo \'Hello this is integration tests \''
},
"End-to-end Tests": {
sh 'echo \'Hello this is end-to-end tests\''
}
)
}
}
stage('Staging') {
steps {
sh '''
docker run -d -v devops_artifacts_data:/artifacts -p 5000:80 --name aspnetcore -w /artifacts microsoft/aspnetcore-build:1.0-1.1 dotnet /artifacts/src.dll
'''
}
}
stage('UAT') {
steps {
sh '''
docker run -d -v devops_artifacts_data:/artifacts -p 5001:80 --name aspnetcore-uat -w /artifacts microsoft/aspnetcore-build:1.0-1.1 dotnet /artifacts/src.dll
'''
}
}
stage('Production') {
steps {
sh '''
docker run -d -v devops_artifacts_data:/artifacts -p 5002:80 --name aspnetcore-prod -w /artifacts microsoft/aspnetcore-build:1.0-1.1 dotnet /artifacts/src.dll
'''
}
}
}
post {
success {
notifySuccessful()
}
failure {
notifyFailed()
}
}
}

def notifyStarted() {
updateGitlabCommitStatus name: 'jenkins', state: 'pending'
slackSend (color: '#FFFF00', message: "STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}

def notifySuccessful() {
updateGitlabCommitStatus name: 'jenkins', state: 'success'
slackSend (color: '#00FF00', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}

def notifyFailed() {
updateGitlabCommitStatus name: 'jenkins', state: 'failed'
slackSend (color: '#FF0000', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
24 changes: 24 additions & 0 deletions templates/aspnetcore/src/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;

namespace src
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}
}
}
37 changes: 37 additions & 0 deletions templates/aspnetcore/src/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace src
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World! Technical Team");
});
}
}
}
15 changes: 15 additions & 0 deletions templates/aspnetcore/src/src.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.0.3" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions templates/aspnetcore/tests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using Xunit;

namespace tests
{
public class UnitTest1
{
[Fact]
public void Test1()
{
// Assert.Equal(1==2);
}
}
}
14 changes: 14 additions & 0 deletions templates/aspnetcore/tests/tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170123-02" />
<PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
</ItemGroup>

</Project>

0 comments on commit ef02e86

Please sign in to comment.