This commit is contained in:
Yadciel 2023-05-12 12:18:49 +02:00
parent 27d545326e
commit 62bd1bd253

View File

@ -1,12 +1,6 @@
pipeline { pipeline {
agent { agent {
label 'python' // Uses the Jenkins agent with the label 'python' label 'python' // Uses the Jenkins agent with the label 'python'
}
environment {
GITEA_API_URL = "https://git.braveslave.duckdns.org/api/v1"
OWNER = "Yadciel"
REPO = "LF08"
FILE_PATH = "C:/Program Files/jenkins-agent/workspace/TS/dist"
} }
stages { stages {
stage('Build') { stage('Build') {
@ -30,61 +24,5 @@ pipeline {
""" """
} }
} }
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!"
}
}
}
} }
} }