1
Files
ss14-launcher-extractor/.jenkinsfile

101 lines
4.1 KiB
Plaintext

pipeline {
agent any
tools {
jdk "Temurin 21"
}
environment {
GITEA_API_URL = "https://di9.ru/git/api/v1/repos/Voomra/ss14-launcher-extractor/releases"
GITEA_TOKEN = credentials("JENKINS_GITEA_ACCESS_TOKEN")
}
stages {
stage("Сборка") {
steps {
sh "./gradlew clean shadowJar"
}
}
stage("Создание релиза") {
steps {
script {
def version = sh(script: './gradlew properties -q | grep "version:" | awk \'{print $2}\'', returnStdout: true).trim()
def releaseData = """
{
"tag_name": "v${version}-test",
"name": "Release v${version}",
"body": "Jenkins автоматически создал релиз",
"draft": false,
"prerelease": false
}
"""
def connection = new URL(env.GITEA_API_URL).openConnection() as HttpURLConnection
connection.setRequestMethod("POST")
connection.setRequestProperty("Authorization", "token ${env.GITEA_TOKEN}")
connection.setRequestProperty("Content-Type", "application/json")
connection.doOutput = true
def writer = new OutputStreamWriter(connection.outputStream)
writer.write(releaseData)
writer.flush()
writer.close()
def responseCode = connection.responseCode
def responseBody = connection.inputStream.text
if (responseCode != 201) {
error """
❌ Ошибка: Gitea вернул HTTP код ${responseCode}. Ожидался 201.
Тело ответа: ${responseBody}
"""
}
def releaseId = new groovy.json.JsonSlurper().parseText(responseBody).id
env.RELEASE_ID = releaseId
}
}
}
stage("Загрузка файлов в релиз") {
steps {
script {
if (!env.RELEASE_ID) {
error "❌ ID релиза не определен. Пропускаем загрузку артефактов."
}
def files = findFiles(glob: 'build/libs/*.jar')
if (files.isEmpty()) {
echo "⚠️ Нет артефактов для загрузки."
return
}
files.each { file ->
def fileName = file.name
echo "Загружаем файл: ${fileName}"
def connection = new URL("${env.GITEA_API_URL}/${env.RELEASE_ID}/assets?name=${fileName}").openConnection() as HttpURLConnection
connection.setRequestMethod("POST")
connection.setRequestProperty("Authorization", "token ${env.GITEA_TOKEN}")
connection.setRequestProperty("Content-Type", "application/octet-stream")
connection.doOutput = true
def fileBytes = new File("build/libs/${fileName}").bytes
connection.outputStream.write(fileBytes)
def uploadResponseCode = connection.responseCode
if (uploadResponseCode != 201) {
echo """
⚠️ Ошибка загрузки ${fileName}: статус ${uploadResponseCode}
Тело ответа: ${connection.inputStream.text}
"""
}
}
}
}
}
}
}