build(ci): загрузка артефактов в релиз
This commit is contained in:
79
.jenkinsfile
79
.jenkinsfile
@@ -6,20 +6,18 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
GITEA_API_URL = "https://di9.ru/git/api/v1"
|
GITEA_API_URL = "https://di9.ru/git/api/v1/repos/Voomra/ss14-launcher-extractor/releases"
|
||||||
GITEA_REPO_OWNER = "Voomra"
|
|
||||||
GITEA_REPO_NAME = "ss14-launcher-extractor"
|
|
||||||
GITEA_TOKEN = credentials("JENKINS_GITEA_ACCESS_TOKEN")
|
GITEA_TOKEN = credentials("JENKINS_GITEA_ACCESS_TOKEN")
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage("Build") {
|
stage("Сборка") {
|
||||||
steps {
|
steps {
|
||||||
sh "./gradlew shadowJar"
|
sh "./gradlew clean shadowJar"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage("Create Gitea Release") {
|
stage("Создание релиза") {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
def version = sh(script: './gradlew properties -q | grep "version:" | awk \'{print $2}\'', returnStdout: true).trim()
|
def version = sh(script: './gradlew properties -q | grep "version:" | awk \'{print $2}\'', returnStdout: true).trim()
|
||||||
@@ -34,16 +32,67 @@ pipeline {
|
|||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def apiResponse = sh(script: '''
|
def connection = new URL(env.GITEA_API_URL).openConnection() as HttpURLConnection
|
||||||
curl -X POST \
|
connection.setRequestMethod("POST")
|
||||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
connection.setRequestProperty("Authorization", "token ${env.GITEA_TOKEN}")
|
||||||
-H "Content-Type: application/json" \
|
connection.setRequestProperty("Content-Type", "application/json")
|
||||||
-d ''' + "'${releaseData}'" + ''' \
|
connection.doOutput = true
|
||||||
"${GITEA_API_URL}/repos/${GITEA_REPO_OWNER}/${GITEA_REPO_NAME}/releases"
|
|
||||||
''', returnStdout: true).trim()
|
|
||||||
|
|
||||||
echo "📥 Ответ от Gitea API:"
|
def writer = new OutputStreamWriter(connection.outputStream)
|
||||||
echo apiResponse
|
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}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user