Updated Jenkins
Added Release Upload
This commit is contained in:
Vendored
+84
-7
@@ -1,7 +1,17 @@
|
||||
pipeline {
|
||||
agent none
|
||||
|
||||
options {
|
||||
skipDefaultCheckout(true)
|
||||
}
|
||||
|
||||
environment {
|
||||
APP_NAME = 'test_app'
|
||||
|
||||
GITEA_URL = 'https://git.grigowashere.ru'
|
||||
GITEA_OWNER = 'Grigo'
|
||||
GITEA_REPO = 'Testing'
|
||||
|
||||
TAIGA_PROJECT_ID = '1'
|
||||
TAIGA_URL = 'https://taiga.grigowashere.ru'
|
||||
}
|
||||
@@ -20,11 +30,15 @@ pipeline {
|
||||
|
||||
cmake --build build/linux
|
||||
|
||||
rm -rf dist/linux
|
||||
mkdir -p dist/linux
|
||||
|
||||
cp build/linux/test_app dist/linux/test_app
|
||||
chmod +x dist/linux/test_app
|
||||
'''
|
||||
|
||||
archiveArtifacts artifacts: 'dist/linux/**', fingerprint: true
|
||||
stash name: 'linux-dist', includes: 'dist/linux/**'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +46,7 @@ pipeline {
|
||||
agent { label 'windows' }
|
||||
|
||||
steps {
|
||||
cleanWs()
|
||||
deleteDir()
|
||||
checkout scm
|
||||
|
||||
bat '''
|
||||
@@ -58,6 +72,68 @@ pipeline {
|
||||
'''
|
||||
|
||||
archiveArtifacts artifacts: 'dist/windows/**', fingerprint: true
|
||||
stash name: 'windows-dist', includes: 'dist/windows/**'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Create Gitea Release') {
|
||||
agent { label 'windows' }
|
||||
|
||||
steps {
|
||||
deleteDir()
|
||||
unstash 'linux-dist'
|
||||
unstash 'windows-dist'
|
||||
|
||||
withCredentials([string(credentialsId: 'Gitea_Credentials', variable: 'GITEA_TOKEN')]) {
|
||||
writeFile file: 'gitea-release.ps1', text: '''
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$tag = "v$env:BUILD_NUMBER"
|
||||
|
||||
Compress-Archive -Path "dist\\windows\\*" -DestinationPath "test_app-windows-$tag.zip" -Force
|
||||
Compress-Archive -Path "dist\\linux\\*" -DestinationPath "test_app-linux-$tag.zip" -Force
|
||||
|
||||
$headers = @{
|
||||
Authorization = "token $env:GITEA_TOKEN"
|
||||
}
|
||||
|
||||
$body = @{
|
||||
tag_name = $tag
|
||||
target_commitish = "main"
|
||||
name = "Release $tag"
|
||||
body = "Jenkins build $env:BUILD_NUMBER`n$env:BUILD_URL"
|
||||
draft = $false
|
||||
prerelease = $false
|
||||
} | ConvertTo-Json
|
||||
|
||||
$release = Invoke-RestMethod `
|
||||
-Method Post `
|
||||
-Uri "$env:GITEA_URL/api/v1/repos/$env:GITEA_OWNER/$env:GITEA_REPO/releases" `
|
||||
-Headers $headers `
|
||||
-ContentType "application/json" `
|
||||
-Body $body
|
||||
|
||||
function Upload-Asset($fileName) {
|
||||
$uploadUrl = "$env:GITEA_URL/api/v1/repos/$env:GITEA_OWNER/$env:GITEA_REPO/releases/$($release.id)/assets?name=$fileName"
|
||||
|
||||
curl.exe -X POST `
|
||||
$uploadUrl `
|
||||
-H "Authorization: token $env:GITEA_TOKEN" `
|
||||
-F "attachment=@$fileName;type=application/zip"
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Gitea asset upload failed: $fileName"
|
||||
}
|
||||
}
|
||||
|
||||
Upload-Asset "test_app-windows-$tag.zip"
|
||||
Upload-Asset "test_app-linux-$tag.zip"
|
||||
'''
|
||||
|
||||
bat '''
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File gitea-release.ps1
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,6 +141,9 @@ pipeline {
|
||||
post {
|
||||
always {
|
||||
node('linux') {
|
||||
cleanWs()
|
||||
checkout scm
|
||||
|
||||
script {
|
||||
def result = currentBuild.currentResult ?: 'UNKNOWN'
|
||||
|
||||
@@ -72,9 +151,9 @@ pipeline {
|
||||
sh(returnStatus: true, script: """
|
||||
set +e
|
||||
|
||||
REF=\$(git log -1 --pretty=%B | grep -oE 'TG-[0-9]+' | head -1 | cut -d- -f2 || true)
|
||||
REF=\\$(git log -1 --pretty=%B | grep -oE 'TG-[0-9]+' | head -1 | cut -d- -f2 || true)
|
||||
|
||||
if [ -z "\$REF" ]; then
|
||||
if [ -z "\\$REF" ]; then
|
||||
echo "No TG-* reference found"
|
||||
exit 0
|
||||
fi
|
||||
@@ -98,8 +177,7 @@ headers = {
|
||||
}
|
||||
|
||||
def get_json(path):
|
||||
url = f"{taiga_url}{path}"
|
||||
req = urllib.request.Request(url, headers=headers)
|
||||
req = urllib.request.Request(f"{taiga_url}{path}", headers=headers)
|
||||
try:
|
||||
with urllib.request.urlopen(req) as r:
|
||||
return json.loads(r.read().decode("utf-8"))
|
||||
@@ -136,9 +214,8 @@ payload = json.dumps({
|
||||
"version": data["version"],
|
||||
}).encode("utf-8")
|
||||
|
||||
url = f"{taiga_url}/api/v1/{endpoint}/{data['id']}"
|
||||
req = urllib.request.Request(
|
||||
url,
|
||||
f"{taiga_url}/api/v1/{endpoint}/{data['id']}",
|
||||
data=payload,
|
||||
headers=headers,
|
||||
method="PATCH",
|
||||
|
||||
Reference in New Issue
Block a user