Files
SHERPA/Jenkinsfile
Samuele Locatelli 63c78b9a34 refresh layout
2021-05-14 07:55:29 +02:00

150 lines
5.2 KiB
Groovy

pipeline {
agent none
stages {
stage('Checkout') {
agent any
steps {
/* calcolo numero versione... diverso x branch MASTER/DEVELOP */
script {
withEnv(['NEXT_BUILD_NUMBER=98']) {
// env.versionNumber = VersionNumber(versionNumberString : '1.3.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true)
env.versionNumber = VersionNumber(versionNumberString : '1.3.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}')
env.APP_NAME = 'SHERPA'
}
}
script {
currentBuild.displayName = "${env.versionNumber}"
if (env.BRANCH_NAME == "develop") {
currentBuild.description = "TEST ${env.versionNumber}"
}
else {
currentBuild.description = "BUILD ${env.versionNumber}"
}
}
/* CAMBIO numero versione in file sorgente!!! */
bat "e:\\fart.exe VersGen\\VersGen.cs 0.0.0.0 ${env.versionNumber} || EXIT /B 0"
}
}
stage('Build') {
agent any
steps {
script {
/* compilo tutti i progetti compresi... */
if (env.BRANCH_NAME == "develop") {
/* CAMBIO numero versione in file sorgente!!! */
bat "e:\\fart.exe VersGen\\VersGen.cs 0.0.0.0 ${env.versionNumber} || EXIT /B 0"
fixNuget("${WORKSPACE}\\SHERPA.sln")
parallel (
REL: {
sleep 0
bat "\"${tool 'MSBuild-15.0'}\" SHERPA/SHERPA.csproj -target:Build /p:Configuration=Release /p:Platform=\"Any CPU\" /p:OutputPath=bin/ /m"
},
failFast: false)
}
else {
echo 'Nothing to Build...'
}
}
}
}
stage('Test') {
steps {
echo 'Testing.. 2 be done...'
}
}
stage('Deploy') {
agent any
steps {
script {
/* DEPLOY condizionale: develop / master */
if (env.BRANCH_NAME == "master") {
/* CAMBIO numero versione in file sorgente!!! */
bat "e:\\fart.exe VersGen\\VersGen.cs 0.0.0.0 ${env.versionNumber} || EXIT /B 0"
fixNuget("${WORKSPACE}\\SHERPA.sln")
parallel (
IIS01: {
bat "\"${tool 'MSBuild-15.0'}\" \"/p:AspnetMergePath=C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v10.0A\\bin\\NETFX 4.6.2 Tools\" /p:DeployOnBuild=true /p:Targets=Publish /p:PublishProfile=IIS01.pubxml /p:VisualStudioVersion=15.0 /p:RunCodeAnalysis=false /p:Configuration=IIS01 /p:username=jenkins /p:Password=viadante16 /p:AllowUntrustedCertificate=true /p:OutputPath=bin/ SHERPA/SHERPA.csproj"
},
IIS02: {
sleep 2;
bat "\"${tool 'MSBuild-15.0'}\" \"/p:AspnetMergePath=C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v10.0A\\bin\\NETFX 4.6.2 Tools\" /p:DeployOnBuild=true /p:Targets=Publish /p:PublishProfile=IIS02.pubxml /p:VisualStudioVersion=15.0 /p:RunCodeAnalysis=false /p:Configuration=IIS02 /p:username=jenkins /p:Password=viadante16 /p:AllowUntrustedCertificate=true /p:OutputPath=bin/ SHERPA/SHERPA.csproj"
},
failFast: false)
}
else {
echo 'Nothing to deploy...'
}
}
}
}
}
post {
success {
sendSlack("Successful", "good")
}
failure {
sendSlack("Failed", "danger")
}
unstable {
sendSlack("Unstable", "warning")
}
}
}
@NonCPS
// Funzione x recupero changeLog
def getChangeString() {
MAX_MSG_LEN = 100
def changeString = ""
echo "Gathering SCM changes"
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
truncated_msg = entry.msg.take(MAX_MSG_LEN)
changeString += " - ${truncated_msg} [${entry.author}]\n"
}
}
if (!changeString) {
changeString = " - Nessuna Modifica"
}
return changeString
}
// Funzione x invio email
def sendEmail(status) {
mail (
to: "$EMAIL_RECIPIENTS",
subject: "${env.versionNumber} " + status +": Build $BUILD_NUMBER ($JOB_NAME)",
body: "Modifiche:\n " + getChangeString() + "\n\n Verifica console output: $BUILD_URL/console" + "\n"
)
}
// Funzione x invio slack
def sendSlack(status, colorCode) {
slackSend (
color: colorCode,
channel: "#sherpa-dev",
failOnError: false,
message: "${env.JOB_NAME} ${env.versionNumber} | " + status + ": Build ${env.BUILD_NUMBER}\n\n" +
"Modifiche:\n " + getChangeString() + "\n\n Verifica build: <${env.BUILD_URL}|Apri>" + "\n"
)
}
// funzione x fix pacchetti nuget da NOSTRO repo Nexus con proxy
def fixNuget(solutionFile) {
// bat "e:\\nuget setapikey fe387daa-d07c-3207-877e-96c8be1be91b -source http://nexus.steamware.net/repository/nuget-group"
// solo la prima volta va aggiunta...
hasSource = bat "e:\\nuget sources list | find \"Steamware\" /C"
if (hasSource == "0")
{
bat "e:\\nuget sources Add -Name \"Steamware Nexus\" -Source http://nexus.steamware.net/repository/nuget-group -username \"nugetUser\" -password \"viaDante16\""
}
else
{
bat "e:\\nuget sources Update -Name \"Steamware Nexus\" -Source http://nexus.steamware.net/repository/nuget-group -username \"nugetUser\" -password \"viaDante16\""
}
bat "e:\\nuget.exe restore ${solutionFile}"
}