eda-viewer/.groovy
2022-05-09 16:48:57 -07:00

268 lines
14 KiB
Groovy

#!/usr/bin/env groovy
/* groovylint-disable CompileStatic, ConsecutiveStringConcatenation, DuplicateNumberLiteral, DuplicateStringLiteral, LineLength, NestedBlockDepth, NoDef, VariableTypeRequired */
import groovy.transform.Field
@Field String _DDrive = 'D:/'
@Field String _ExePath = '...'
@Field String _NGINXFile = '...'
@Field String _PortNumber = '...'
@Field String _AssemblyName = '...'
@Field String _NetVersion = 'net6.0'
@Field String _TargetLocation = '...'
@Field String _GitCommitSeven = '...'
@Field String _GitName = 'EDA-Viewer'
@Field String _FirstBeforePlus = '5000'
@Field String _MonARessource = 'EDA_Viewer'
@Field String _ProjectDirectory = 'EDA Viewer'
@Field String _WorkingDirectoryName = 'IFXApps'
@Field String _AgentStaging = 'mestsa07ec-ecmeseaf'
@Field String _AgentProduction = 'messa08ec-ecmeseaf'
@Field String _DDriveNet = "${_DDrive}${_NetVersion}"
@Field String _CredentialsId = 'EDA-Username-Password'
@Field String _AgentDevelopment = 'mestsa003-mesedasvc'
@Field String _Company = 'Infineon Technologies Americas Corp.'
@Field String _ProgramFilesDotnet = 'C:/program files/dotnet/dotnet.exe'
pipeline {
agent {
label env.JENKINS_ENVIRONMENT == 'Development' ? _AgentDevelopment : env.JENKINS_ENVIRONMENT == 'Staging' ? _AgentStaging : env.JENKINS_ENVIRONMENT == 'Production' ? _AgentProduction : 'Else'
}
parameters {
string(name: 'MONA_SUFFIX', defaultValue: env.JENKINS_ENVIRONMENT == 'Development' ? '_IFX' : '_EC', description: 'MonA Suffix')
string(name: 'GIT_SERVER', defaultValue: env.JENKINS_ENVIRONMENT == 'Development' ? 'mestsa003.infineon.com' : 'mestsa07ec.ec.local', description: 'git server')
string(name: 'DEFAULT_FILE_SERVER', defaultValue: env.JENKINS_ENVIRONMENT == 'Development' ? 'messv02ecc1_ec_local' : 'messv02ecc1.ec.local', description: 'Default file server...')
}
stages {
stage('Git') {
steps {
bat(returnStatus: true, script: 'git init')
bat(returnStatus: true, script: 'git remote add origin \\\\' + params.GIT_SERVER + '\\Git\\' + _GitName + '.git')
bat(returnStatus: true, script: 'git pull origin master')
}
}
stage('Setup') {
steps {
script {
_AssemblyName = "${env.JOB_NAME}"
_GitCommitSeven = '1234567'
// _GitCommitSeven = env.GIT_COMMIT.substring(0, 7)
dir(_ProjectDirectory) {
def files = findFiles(glob: '*.csproj')
if (files.length != 1) {
error("Build failed because couldn't find a *.csproj file")
}
echo """
${files[0].name}
${files[0].path}
${files[0].directory}
${files[0].length}
${files[0].lastModified}
"""
_AssemblyName = files[0].name.split('[.]csproj')[0]
}
_TargetLocation = "\\\\${params.DEFAULT_FILE_SERVER}\\EC_EAFRepository\\${env.JENKINS_ENVIRONMENT}\\DeploymentStorage\\Adaptation_${_AssemblyName}"
withCredentials([usernamePassword(credentialsId: _CredentialsId, passwordVariable: 'password', usernameVariable: 'username')]) {
dir("C:/Users/${username}/AppData/Local/IFXApps/nginx-1.20.1/conf/includes") {
_NGINXFile = "C:/Users/${username}/AppData/Local/IFXApps/nginx-1.20.1/conf/includes/${_AssemblyName}.conf"
def files = findFiles(glob: "${_AssemblyName}.conf")
if (files.length != 1) {
writeFile(file: _NGINXFile, text: "location / { proxy_pass http://localhost:${_FirstBeforePlus}; }")
}
}
}
}
}
}
stage('Read NGINX') {
steps {
script {
String text = readFile(file: _NGINXFile)
String check = text == null ? _FirstBeforePlus : text.split(';')[0]
String[] segments = check.split(':')
if (segments.length != 3) {
_PortNumber = check
}
else {
_PortNumber = (segments[2].toInteger() + 2).toString()
}
_ExePath = "${_DDriveNet}/${_GitCommitSeven}-${env.BUILD_NUMBER}-${_PortNumber}-${env.JOB_NAME}/${_AssemblyName}.exe"
}
}
}
stage('Info') {
steps {
// echo "GIT_URL_N - ${env.GIT_URL_N}"
// echo "BRANCH_NAME ${env.BRANCH_NAME}"
// echo "DEPLOY_VERSION ${env.DEPLOY_VERSION}"
// echo "GIT_AUTHOR_NAME ${env.GIT_AUTHOR_NAME}"
// echo "GIT_LOCAL_BRANCH ${env.GIT_LOCAL_BRANCH}"
// echo "GIT_COMMITTER_EMAIL ${env.GIT_COMMITTER_EMAIL}"
// echo "GIT_PREVIOUS_COMMIT ${env.GIT_PREVIOUS_COMMIT}"
// echo "GIT_PREVIOUS_SUCCESSFUL_COMMIT ${env.GIT_PREVIOUS_SUCCESSFUL_COMMIT}"
echo "_AssemblyName ${_AssemblyName}" // ...
echo "_ExePath ${_ExePath}" // ...
echo "_PortNumber ${_PortNumber}" // ...
echo "BUILD_NUMBER ${env.BUILD_NUMBER}" // 11
echo "DEFAULT_FILE_SERVER ${params.DEFAULT_FILE_SERVER}" // 11
echo "GIT_BRANCH ${env.GIT_BRANCH}" // origin/master
echo "GIT_COMMIT ${env.GIT_COMMIT}" // 73b814069f2cf0173a62a8228815a9bc9ba93c41
echo "GIT_SERVER ${params.GIT_SERVER}" // ...
echo "GIT_URL ${env.GIT_URL}" // D:\ProgramData\Git\....git
echo "JENKINS_ENVIRONMENT ${env.JENKINS_ENVIRONMENT}" // 11
echo "JENKINS_URL ${env.JENKINS_URL}" // http://localhost:8080/
echo "JOB_NAME ${env.JOB_NAME}" // ...
echo "WORKSPACE ${env.WORKSPACE}" // D:\.jenkins\_\...
}
}
// stage('Restore') {
// steps {
// bat(returnStatus: true, script: 'dotnet --info')
// }
// }
stage('Safe storage of app secrets') {
steps {
withCredentials([usernamePassword(credentialsId: _CredentialsId, passwordVariable: 'password', usernameVariable: 'username')]) {
dir(_ProjectDirectory) {
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
'user-secrets init')
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
'user-secrets set "Company" "' + _Company + '"')
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
'user-secrets set "ServiceUser" "' + username + '"')
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
'user-secrets set "BuildNumber" "' + env.BUILD_NUMBER + '"')
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
'user-secrets set "GitCommitSeven" "' + _GitCommitSeven + '"')
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
'user-secrets set "Server" "' + params.DEFAULT_FILE_SERVER + '"')
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
'user-secrets set "URLs" "' + 'http://localhost:' + _PortNumber)
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
'user-secrets set "WorkingDirectoryName" "' + _WorkingDirectoryName + '"')
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
'user-secrets set "MonARessource" "' + _MonARessource + env.MONA_SUFFIX + '"')
}
}
}
}
// stage('Core Build (packagemanagement.eu.infineon.com)') {
// steps {
// echo "Build number is ${currentBuild.number}"
// dir(_ProjectDirectory) {
// bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
// 'build --runtime win-x64 --self-contained --verbosity quiet --source ' +
// 'https://packagemanagement.eu.infineon.com:4430/api/v2/')
// }
// }
// }
stage('Core Build') {
steps {
echo "Build number is ${currentBuild.number}"
dir(_ProjectDirectory) {
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
'build --runtime win-x64 --self-contained --verbosity quiet')
}
}
}
stage('Commit Id') {
steps {
dir(_ProjectDirectory) {
writeFile(file: 'bin/Debug/' + _NetVersion + "/win-x64/${env.GIT_COMMIT}-${env.BUILD_NUMBER}.txt", text: "${env.GIT_URL}")
}
}
}
// stage('Test') {
// options {
// timeout(time: 10, unit: 'MINUTES')
// }
// steps {
// dir(_ProjectDirectory) {
// bat('dotnet --info')
// }
// }
// }
// stage('Version') {
// steps {
// bat('dotnet --info')
// }
// }
stage('Package') {
steps {
dir(_ProjectDirectory) {
fileOperations([fileZipOperation(folderPath: 'bin/Debug/' + _NetVersion + '/win-x64', outputFolderPath: "${_DDriveNet}/${_GitCommitSeven}-${env.BUILD_NUMBER}-${_PortNumber}-${env.JOB_NAME}-Debug")])
fileOperations([fileCopyOperation(excludes: '', flattenFiles: true, includes: "${_AssemblyName}*", renameFiles: false, sourceCaptureExpression: '', targetLocation: "${_DDriveNet}/${_GitCommitSeven}-${env.BUILD_NUMBER}-${_PortNumber}-${env.JOB_NAME}-Debug", targetNameExpression: '')])
}
}
}
stage('Publish') {
steps {
dir(_ProjectDirectory) {
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
'remove reference "../Client/' + env.JOB_NAME + '.Client.csproj"')
bat(returnStatus: true, script: '"' + _ProgramFilesDotnet + '" ' +
'publish --configuration Release --runtime win-x64 --verbosity quiet ' +
"--self-contained true --p:Version=6.0.202-${_GitCommitSeven}-${env.BUILD_NUMBER} -o " +
'"' + "${_DDriveNet}/${_GitCommitSeven}-${env.BUILD_NUMBER}-${_PortNumber}-${env.JOB_NAME}" + '"')
}
}
}
stage('Service') {
steps {
withCredentials([usernamePassword(credentialsId: _CredentialsId, passwordVariable: 'password', usernameVariable: 'username')]) {
bat(returnStatus: true, script: 'sc create "' + "${env.JOB_NAME}-${_PortNumber}" + '" ' +
'start= delayed-auto DisplayName="' + "${env.JOB_NAME}-${_PortNumber}" + '" ' +
'binPath= "' + _ExePath + '" ' +
'obj= "' + "${env.USERDOMAIN}\\${username}" + '" password= "' + password + '"')
bat(returnStatus: true, script: 'sc start "' + "${env.JOB_NAME}-${_PortNumber}" + '"')
}
}
}
stage('Upadate NGINX') {
steps {
writeFile(file: _NGINXFile, text: "location / { proxy_pass http://localhost:${_PortNumber}; }")
}
}
stage('NGINX Test and Reload') {
steps {
withCredentials([usernamePassword(credentialsId: _CredentialsId, passwordVariable: 'password', usernameVariable: 'username')]) {
dir("C:/Users/${username}/AppData/Local/IFXApps/nginx-1.20.1") {
script {
int returnStatus = bat(returnStatus: true, script: 'nginx.exe -t')
println("returnStatus ################ ${returnStatus} ####################")
if (returnStatus == 0) {
bat(returnStatus: true, script: 'nginx.exe -s reload')
}
}
}
}
}
}
// stage('Force Fail') {
// steps {
// error("Build failed because of this and that..")
// }
// }
// stage('Copy Files to: file-share') {
// steps {
// dir(_ProjectDirectory + '/bin/Debug/' + _NetVersion + '/win-x64') {
// fileOperations([fileCopyOperation(excludes: '', flattenFiles: true, includes: "${_AssemblyName}*.txt", renameFiles: false, sourceCaptureExpression: '', targetLocation: _TargetLocation, targetNameExpression: '')])
// fileOperations([fileCopyOperation(excludes: '', flattenFiles: true, includes: "${_AssemblyName}*.dll", renameFiles: false, sourceCaptureExpression: '', targetLocation: _TargetLocation, targetNameExpression: '')])
// fileOperations([fileCopyOperation(excludes: '', flattenFiles: true, includes: "${_AssemblyName}*.exe", renameFiles: false, sourceCaptureExpression: '', targetLocation: _TargetLocation, targetNameExpression: '')])
// fileOperations([fileCopyOperation(excludes: '', flattenFiles: true, includes: "${_AssemblyName}*.pdb", renameFiles: false, sourceCaptureExpression: '', targetLocation: _TargetLocation, targetNameExpression: '')])
// }
// }
// }
}
post {
always {
dir(_ProjectDirectory + '/bin') {
deleteDir()
}
dir(_ProjectDirectory + '/obj') {
deleteDir()
}
// cleanWs()
}
}
}