LF08/jenkinsfile

92 lines
2.8 KiB
Plaintext
Raw Normal View History

2023-04-26 10:13:42 +02:00
pipeline {
2023-04-26 10:59:56 +02:00
agent {
2023-04-27 10:10:20 +02:00
label 'python' // Uses the Jenkins agent with the label 'python'
2023-05-12 12:09:57 +02:00
}
environment {
GITEA_API_URL = "https://git.braveslave.duckdns.org/api/v1"
GITEA_ACCESS_TOKEN = credentials('9afe425f01f873c384e4454f00ee38110057de30')
OWNER = "Yadciel"
REPO = "LF08"
FILE_PATH = "C:/Program Files/jenkins-agent/workspace/TS/dist"
2023-04-26 10:59:56 +02:00
}
2023-04-26 10:13:42 +02:00
stages {
stage('Build') {
steps {
bat """
@echo off
2023-04-27 10:10:20 +02:00
rem Set the path to the workspace directory
cd C:/Program Files/jenkins-agent/workspace/TS
2023-04-26 10:13:42 +02:00
2023-04-27 10:10:20 +02:00
rem Delete the "dist" folder if it exists
2023-04-27 09:58:50 +02:00
if exist dist rmdir /s /q dist
2023-04-27 10:10:20 +02:00
rem Use PyInstaller to compile the Python application into a single executable file
2023-04-27 09:53:48 +02:00
python -m PyInstaller --onefile main.py
2023-04-27 09:47:26 +02:00
2023-04-27 10:10:20 +02:00
rem Move the "resources" folder into the "dist" folder
move resources dist
2023-04-26 10:13:42 +02:00
2023-04-27 10:10:20 +02:00
rem Output a success message
echo Resources folder was successfully moved to the dist folder.
2023-04-26 10:13:42 +02:00
"""
}
2023-05-11 19:55:14 +02:00
}
2023-05-12 12:09:57 +02:00
stage('Check for Release Tag') {
steps {
script {
def response = sh(returnStdout: true, script: "git describe --tags --exact-match HEAD")
if (response.trim() == "") {
error("No release tag found on the latest commit.")
}
env.RELEASE_TAG = response.trim()
}
}
}
stage('Create Release') {
when {
expression { env.RELEASE_TAG != null }
}
steps {
script {
def payload = [
tag_name: env.RELEASE_TAG,
name: "Release ${env.RELEASE_TAG}"
]
def response = httpRequest(
url: "${env.GITEA_API_URL}/repos/${env.OWNER}/${env.REPO}/releases?access_token=${env.GITEA_ACCESS_TOKEN}",
httpMode: 'POST',
contentType: 'APPLICATION_JSON',
requestBody: new groovy.json.JsonBuilder(payload).toString()
)
if (response.status != 201) {
error("Failed to create release: ${response.content}")
}
def releaseId = new groovy.json.JsonSlurper().parseText(response.content).id
env.RELEASE_ID = releaseId.toString()
}
}
}
stage('Upload File') {
when {
expression { env.RELEASE_ID != null }
}
steps {
script {
def response = httpRequest(
url: "${env.GITEA_API_URL}/repos/${env.OWNER}/${env.REPO}/releases/${env.RELEASE_ID}/assets?access_token=${env.GITEA_ACCESS_TOKEN}",
httpMode: 'POST',
contentType: 'APPLICATION_OCTET_STREAM',
requestBody: new File(env.FILE_PATH)
)
if (response.status != 201) {
error("Failed to upload file: ${response.content}")
}
echo "File uploaded successfully!"
}
}
}
2023-04-26 10:13:42 +02:00
}
2023-05-11 19:55:14 +02:00
}