Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
266 changes: 266 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
import hudson.model.Result
import jenkins.model.CauseOfInterruption
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException

def haltBuildWithSuccess() {
currentBuild.rawBuild.@result = Result.SUCCESS
def cause = new CauseOfInterruption.UserInterruption("Build halted programmatically with SUCCESS status")
throw new FlowInterruptedException(Result.SUCCESS, false, cause)
}

pipeline {
agent any

environment {
github_pat = credentials('github-pat')
devBranch = "development"
mainBranch = "master"
NUGET_PACKAGES = "D:\\NuGetCache"
}

stages {
stage('Prepare Environment') {
steps {
script {
// Set current Version
def fileContent = powershell(returnStdout: true, script: '''
Get-Content -Path "./scripts/OpenSEE.version" -Raw
''').trim()
env.openSEEVersion = fileContent
println("openSEE version: ${env.openSEEVersion}")
}
script {
//Set current Commit
env.GIT_COMMIT = bat(script: '@git rev-parse HEAD', returnStdout: true).trim()
println("Current Git Commit: ${env.GIT_COMMIT}")
}
script {
//Get last release from git tags
bat( script: "@git fetch origin ${env.mainBranch}:refs/remotes/origin/${env.mainBranch}")
def mainCommit = bat(script: "@git rev-parse origin/${env.mainBranch}", returnStdout: true).trim()
try {
env.LAST_RELEASE_TAG = bat(script: "@git describe --tags --abbrev=0 ${mainCommit}", returnStdout: true).trim()
}
catch (Exception ex) {
println("No tags found, setting LAST_RELEASE_TAG to v2.0.0")
env.LAST_RELEASE_TAG = "v2.0.0"
}
println("Last Release Tag: ${env.LAST_RELEASE_TAG}")
}
}
}

stage('Check Conditions') {
when {
anyOf {
not {
anyOf {
expression { env.BRANCH_NAME.startsWith("PR") }
expression { env.BRANCH_NAME == "${env.mainBranch}" }
}
}
allOf {
expression { env.BRANCH_NAME.startsWith("PR") }
expression { env.CHANGE_BRANCH != "${env.devBranch}" }
}
allOf {
expression { env.BRANCH_NAME.startsWith("PR") }
expression { env.CHANGE_TARGET != "${env.mainBranch}" }
}
}
}
steps {
haltBuildWithSuccess()
}
}

stage('Checkout Master Branch') {
when {
expression {
return env.BRANCH_NAME == "${env.mainBranch}"
}
}
steps {
script {
bat(script: "@git fetch origin ${env.BRANCH_NAME}:refs/remotes/origin/${env.BRANCH_NAME}")
bat(script: "@git checkout origin/${env.BRANCH_NAME}")
}
}
}

stage('Checkout Development Branch') {
when {
expression {
return env.CHANGE_BRANCH == "${env.devBranch}"
}
}
steps {
script {
bat(script: "@git fetch origin ${env.CHANGE_BRANCH}:refs/remotes/origin/${env.CHANGE_BRANCH}")
bat(script: "@git checkout origin/${env.CHANGE_BRANCH}")
}
}
}

stage('Application Version') {
when {
expression {
return env.BRANCH_NAME != "${env.mainBranch}"
}
}
steps {
script {
env.GIT_COMMIT = bat(script: '@git rev-parse HEAD', returnStdout: true).trim()
}
powershell "powershell.exe -File .\\scripts\\Versioning.ps1 -VersionFile './scripts/OpenSEE.version' -Commit false"
bat(script: "@git add scripts/OpenSEE.version")
bat(script: "git diff --cached --quiet || git commit -m \"Updated Version Number\"")
}
}

stage('Gemstone Updates') {
when {
expression {
return env.BRANCH_NAME != "${env.mainBranch}"
}
}
steps {
powershell "powershell.exe -File .\\scripts\\GemstoneUpdates.ps1 -VersionFile './src/Directory.Build.props'"
powershell "powershell.exe -File .\\scripts\\CreateDependencyPR.ps1 -GithubToken '${github_pat}' -DevelopmentBranchName '${devBranch}'"
script {
bat(script: "@git add src/Directory.Build.props")
bat(script: "git diff --cached --quiet || git commit -m \"Updated Dependencies\"")
}
}
}

stage('Push Changes') {
when {
allOf {
expression {
return env.BRANCH_NAME != "${env.mainBranch}"
}
expression {
return bat(script: '@git rev-parse HEAD', returnStdout: true).trim() != env.GIT_COMMIT
}
}
}
steps {
powershell "git push origin HEAD:${env.devBranch}"
haltBuildWithSuccess()
}
}

stage('Build Production UI') {
steps {
dir('src/OpenSEE') {
bat(script: 'npm run build')
}
}
}

stage('Build Docker Images') {
when {
anyOf {
expression {
return env.CHANGE_BRANCH == "${env.devBranch}"
}
expression {
return env.BRANCH_NAME == "${env.mainBranch}"
}
}
}
steps {
script {
env.openSEEDockerTag = env.CHANGE_BRANCH == "${env.devBranch}" ? "${env.openSEEVersion}a" : env.openSEEVersion
println("Building openSEE Docker image tag: opensee:${env.openSEEDockerTag}")
}

powershell "msbuild /t:Publish /p:DeployOnBuild=true';'Configuration=Release';'PublishProfile='Docker Release Profile openSEE' './src/OpenSEE/OpenSEE.csproj' /nodeReuse:false -restore"
powershell "docker build --build-arg CONFIGURATION=Release -f .\\openSEE.dockerfile -t opensee:${env.openSEEDockerTag} ."
}
}

stage('Publish Application') {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very different from the other apps.
Is there a reason we can't just use a Publish Profile?

steps {
powershell """
dotnet publish '.\\src\\OpenSEE\\OpenSEE.csproj' `
'-p:PublishProfile=Release Profile openSEE'
"""
}
}

stage('Package Application') {
steps {
script {
if (!env.WEBHOST_DELIVERY_DIRECTORY?.trim()) {
error('WEBHOST_DELIVERY_DIRECTORY is not configured in Jenkins.')
}

env.archiveName = env.BRANCH_NAME == "${env.mainBranch}" ?
"openSEE_v${env.openSEEVersion}.zip" :
"openSEE_v${env.openSEEVersion}a.zip"
}
powershell """
[xml]\$publishProfile = Get-Content `
-LiteralPath '.\\src\\OpenSEE\\Properties\\PublishProfiles\\Release Profile openSEE.pubxml' `
-Raw
\$publishDir = (\$publishProfile.Project.PropertyGroup |
Where-Object { \$_.PublishDir }).PublishDir

Compress-Archive `
-Path (Join-Path '.\\src\\OpenSEE' "\$publishDir*") `
-DestinationPath '${WORKSPACE}\\${env.archiveName}' `
-Force
"""
}
}

stage('Comment Prerelease') {
when {
expression {
return env.CHANGE_BRANCH == "${env.devBranch}"
}
}
steps {
powershell """
powershell.exe -File .\\scripts\\GithubComment.ps1 `
-Comment 'Prerelease openSEE v${env.openSEEVersion}a is available.' `
-BranchName '${env.devBranch}' `
-GithubToken '${github_pat}' `
-RepoOwner 'GridProtectionAlliance' `
-RepoName 'openSEE'
"""
}
}

stage('Deploy Prerelease') {
when {
expression {
return env.CHANGE_BRANCH == "${env.devBranch}"
}
}
steps {
powershell "Move-Item -Path '${WORKSPACE}\\${env.archiveName}' -Destination '${env.WEBHOST_DELIVERY_DIRECTORY}\\openSEE\\PreRelease\\${env.archiveName}' -Force"
}
}

stage('Deploy Release') {
when {
allOf {
expression {
return env.BRANCH_NAME == "${env.mainBranch}"
}
expression {
return env.openSEEVersion != env.LAST_RELEASE_TAG
}
}
}
steps {
powershell "Move-Item -Path '${WORKSPACE}\\${env.archiveName}' -Destination '${env.WEBHOST_DELIVERY_DIRECTORY}\\openSEE\\${env.archiveName}' -Force"
powershell "git tag -a v${env.openSEEVersion} -m 'Version ${env.openSEEVersion} release'"
powershell "git push origin --tags"
}
}
}
}
21 changes: 21 additions & 0 deletions openSEE.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Use the official .NET 9.0 runtime as the base image
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
ARG CONFIGURATION="Development"

# Set the working directory inside the container
WORKDIR /openSEE

# Copy openSEE from the local published folder to the container
COPY ./[Bb]uild/${CONFIGURATION}/Applications/openSEE/net9.0/publish/linux-x64/ /openSEE/

# Set permissions for all copied folders and files
RUN chmod -R 777 /openSEE

# Ensure the application is executable
RUN chmod +x /openSEE/OpenSEE

# Expose the webserver port
EXPOSE 8080

# Define the entry point to run
ENTRYPOINT ["sh", "-c", "exec /openSEE/OpenSEE"]
27 changes: 0 additions & 27 deletions scripts/BuildNightly.bat

This file was deleted.

46 changes: 0 additions & 46 deletions scripts/BuildTSX.ps1

This file was deleted.

Loading