From ef02e86fefb6dee8bdaeb9b1f5b0c53eb03e1566 Mon Sep 17 00:00:00 2001 From: Phi Huynh Date: Thu, 20 Apr 2017 22:49:47 +0700 Subject: [PATCH] #6 Adding slack integration --- templates/aspnetcore/Jenkinsfile | 91 +++++++++++++++++++++++++ templates/aspnetcore/src/Program.cs | 24 +++++++ templates/aspnetcore/src/Startup.cs | 37 ++++++++++ templates/aspnetcore/src/src.csproj | 15 ++++ templates/aspnetcore/tests/UnitTest1.cs | 14 ++++ templates/aspnetcore/tests/tests.csproj | 14 ++++ 6 files changed, 195 insertions(+) create mode 100644 templates/aspnetcore/Jenkinsfile create mode 100755 templates/aspnetcore/src/Program.cs create mode 100755 templates/aspnetcore/src/Startup.cs create mode 100755 templates/aspnetcore/src/src.csproj create mode 100755 templates/aspnetcore/tests/UnitTest1.cs create mode 100755 templates/aspnetcore/tests/tests.csproj diff --git a/templates/aspnetcore/Jenkinsfile b/templates/aspnetcore/Jenkinsfile new file mode 100644 index 0000000..e762856 --- /dev/null +++ b/templates/aspnetcore/Jenkinsfile @@ -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})") +} \ No newline at end of file diff --git a/templates/aspnetcore/src/Program.cs b/templates/aspnetcore/src/Program.cs new file mode 100755 index 0000000..5f58593 --- /dev/null +++ b/templates/aspnetcore/src/Program.cs @@ -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() + .Build(); + + host.Run(); + } + } +} diff --git a/templates/aspnetcore/src/Startup.cs b/templates/aspnetcore/src/Startup.cs new file mode 100755 index 0000000..e4745ee --- /dev/null +++ b/templates/aspnetcore/src/Startup.cs @@ -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"); + }); + } + } +} diff --git a/templates/aspnetcore/src/src.csproj b/templates/aspnetcore/src/src.csproj new file mode 100755 index 0000000..ffc2303 --- /dev/null +++ b/templates/aspnetcore/src/src.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp1.0 + + + + + + + + + + + diff --git a/templates/aspnetcore/tests/UnitTest1.cs b/templates/aspnetcore/tests/UnitTest1.cs new file mode 100755 index 0000000..2e942f7 --- /dev/null +++ b/templates/aspnetcore/tests/UnitTest1.cs @@ -0,0 +1,14 @@ +using System; +using Xunit; + +namespace tests +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + // Assert.Equal(1==2); + } + } +} diff --git a/templates/aspnetcore/tests/tests.csproj b/templates/aspnetcore/tests/tests.csproj new file mode 100755 index 0000000..eb425ed --- /dev/null +++ b/templates/aspnetcore/tests/tests.csproj @@ -0,0 +1,14 @@ + + + + Exe + netcoreapp1.0 + + + + + + + + +