92 lines
2.8 KiB
Plaintext
92 lines
2.8 KiB
Plaintext
pipeline {
|
|
agent {
|
|
label 'python' // Uses the Jenkins agent with the label 'python'
|
|
}
|
|
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"
|
|
}
|
|
stages {
|
|
stage('Build') {
|
|
steps {
|
|
bat """
|
|
@echo off
|
|
rem Set the path to the workspace directory
|
|
cd C:/Program Files/jenkins-agent/workspace/TS
|
|
|
|
rem Delete the "dist" folder if it exists
|
|
if exist dist rmdir /s /q dist
|
|
|
|
rem Use PyInstaller to compile the Python application into a single executable file
|
|
python -m PyInstaller --onefile main.py
|
|
|
|
rem Move the "resources" folder into the "dist" folder
|
|
move resources dist
|
|
|
|
rem Output a success message
|
|
echo Resources folder was successfully moved to the dist folder.
|
|
"""
|
|
}
|
|
}
|
|
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!"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|