Skip to content

joostvdg/c-sharp-example-2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Wintel Pipeline

Jenkins

First, see the Jenkinsfile for the pipeline definition.

Example

node ('windows') {
    timestamps{
        stage('Checkout') {
            git credentialsId: 'joost-github', url: 'https://github.com/joostvdg/c-sharp-example.git'
        }

        def sonarHome = tool name: 'SonarQubeScannerMS', type: 'hudson.plugins.sonar.MsBuildSQRunnerInstallation'
        stage('Sonar Start'){
            // start
            bat "\"${sonarHome}\\MSBuild.SonarQube.Runner.exe\" begin /key:ProjectKey /name:ProjectName /version:1.0"
        }

        stage('Build'){
            def msbuildHome = tool name: 'default', type: 'hudson.plugins.msbuild.MsBuildInstallation'
            echo "msbuildHome=${msbuildHome}"
            bat "\"${msbuildHome}\\msbuild\" /t:Rebuild"
        }

        stage('Sonar Finish'){
            // finish
            // step([$class: 'MsBuildSQRunnerEnd'])
            bat "\"${sonarHome}\\MSBuild.SonarQube.Runner.exe\" end"
        }

        stage('Publish NuGet Package') {
            withCredentials([[$class: 'FileBinding', credentialsId: 'nuget', variable: 'nuget']]) {
                withCredentials([[$class: 'StringBinding', credentialsId: 'nuget-api-key', variable: 'key']]) {
                    println "env.nuget=${env.nuget}"
                    println "env.key=${env.key}"
                    // bat "\"${env.nuget}\" setApiKey ${env.key} -Source http://localhost:32769/repository/nuget-hosted"
                    bat "\"${env.nuget}\" pack Package.nuspec"
                    bat "\"${env.nuget}\" push Package.1.0.0.nupkg ${env.key} -Source http://localhost:32769/repository/nuget-hosted"
                }
            }
        }
    }
}

Requires nuspec

The packaging with nuget requires a nuspec file.
You can generate this with the nuget.exe as follows:

nuget spec

Required plugins

  • nuget plugin
  • sonarqube plugin
  • msbuild plugin
  • credentials plugin
  • plain credentials plugin
  • credentials binding plugin

Required tools

  • msbuild v12.0+
  • sonarqube for msbuild
  • nuget

Windows node

  • msbuild v12.0 or higher
  • sonarqube for msbuild installer
  • tool locations configured in node configuration

Slave configuration

Jenkins configuration

  • put all jobs in a Folder
  • add nuget API key for Nexus 3 into secret text credential on Folder
  • add nuget.exe as secret file credential (can be folder, can be global)

Nexus

NuGet Gallery

Currently only v2 of the NuGet API is supported.

Support for the v3 API doesn't seem to be a priority. There is little chance that this functionality will make it into Nexus 3 in 2016.

Evidence for this:

NuGet plugin

https://wiki.jenkins-ci.org/display/JENKINS/Nuget+Plugin

Nexus 3 (3.0.2-02)

NuGet key (ZEPHYR)

  • Nuget Key: d11d6fee-8eac-3aeb-ac15-8f9477235968
  • nuget setapikey d11d6fee-8eac-3aeb-ac15-8f9477235968

Rest call to retrieve the key

GET security token

{
    "action":"rapture_Security",
    "method":"authenticationToken",
    "data":["YWRtaW4=","YWRtaW4xMjM="],
    "type":"rpc",
    "tid":21
}

GET NUGET API KEY

{
    "action":"nuget_NuGetApiKey",
    "method":"readKey",
    "data":["fXZ2NuA4XNuqooojIXy1HXeWardBDZSaKQZ35YWQB8FyaeFGk2dPqM5VddBIMZ1uTav1T1HySxKuWGPx+PdOk7JO"],
    "type":"rpc",
    "tid":22
}

SonarQube

SonarQube API Key

As of SonarQube 5, it requires an API Key.

  • Zephyr: 5459d8e4d84302dbf9578db5192c37b7b092a7b9

Test Coverage

Requirements:

  • OpenCover
  • register open cover x64 profiler
      regsvr32 /s C:\Users\derek.wilson\AppData\Local\Apps\OpenCover\x64\OpenCover.Profiler.dll
    
  • XUnitRunner Package
  • run xunit with -noshadow
stage('Lib::UnitTests') {
    bat '"C:\\Users\\Joost\\AppData\\Local\\Apps\\OpenCover\\OpenCover.Console.exe" -output:"opencover.xml" -register:Path64 -target:"packages\\xunit.runner.console.2.1.0\\tools\\xunit.console.exe" -targetargs:"Coesd.Lib.Cs.ConsoleWriteTest\\bin\\Debug\\Coesd.Lib.Cs.ConsoleWriteTest.dll -xml XUnitResults.xml -noshadow" -filter:"+[*]* -[Coesd.Lib.Cs.ConsoleWriteTest]*"'
}

Example

C:\Users\derek.wilson\AppData\Local\Apps\OpenCover\opencover.console -output:coverage.xml -target:"C:\Program Files (x86)\xUnit\xunit.console.clr4.exe" -targetargs:"MyApp.xunit" -filter:"+[*]MyApp.* -[*.Tests]*"
C:\Users\derek.wilson\AppData\Local\Apps\ReportGenerator\bin\reportgenerator coverage.xml .\coverage

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published