Updated Jenkins
Added Release Upload
This commit is contained in:
Vendored
+84
-7
@@ -1,7 +1,17 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent none
|
agent none
|
||||||
|
|
||||||
|
options {
|
||||||
|
skipDefaultCheckout(true)
|
||||||
|
}
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
|
APP_NAME = 'test_app'
|
||||||
|
|
||||||
|
GITEA_URL = 'https://git.grigowashere.ru'
|
||||||
|
GITEA_OWNER = 'Grigo'
|
||||||
|
GITEA_REPO = 'Testing'
|
||||||
|
|
||||||
TAIGA_PROJECT_ID = '1'
|
TAIGA_PROJECT_ID = '1'
|
||||||
TAIGA_URL = 'https://taiga.grigowashere.ru'
|
TAIGA_URL = 'https://taiga.grigowashere.ru'
|
||||||
}
|
}
|
||||||
@@ -20,11 +30,15 @@ pipeline {
|
|||||||
|
|
||||||
cmake --build build/linux
|
cmake --build build/linux
|
||||||
|
|
||||||
|
rm -rf dist/linux
|
||||||
mkdir -p dist/linux
|
mkdir -p dist/linux
|
||||||
|
|
||||||
cp build/linux/test_app dist/linux/test_app
|
cp build/linux/test_app dist/linux/test_app
|
||||||
|
chmod +x dist/linux/test_app
|
||||||
'''
|
'''
|
||||||
|
|
||||||
archiveArtifacts artifacts: 'dist/linux/**', fingerprint: true
|
archiveArtifacts artifacts: 'dist/linux/**', fingerprint: true
|
||||||
|
stash name: 'linux-dist', includes: 'dist/linux/**'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +46,7 @@ pipeline {
|
|||||||
agent { label 'windows' }
|
agent { label 'windows' }
|
||||||
|
|
||||||
steps {
|
steps {
|
||||||
cleanWs()
|
deleteDir()
|
||||||
checkout scm
|
checkout scm
|
||||||
|
|
||||||
bat '''
|
bat '''
|
||||||
@@ -58,6 +72,68 @@ pipeline {
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
archiveArtifacts artifacts: 'dist/windows/**', fingerprint: true
|
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 {
|
post {
|
||||||
always {
|
always {
|
||||||
node('linux') {
|
node('linux') {
|
||||||
|
cleanWs()
|
||||||
|
checkout scm
|
||||||
|
|
||||||
script {
|
script {
|
||||||
def result = currentBuild.currentResult ?: 'UNKNOWN'
|
def result = currentBuild.currentResult ?: 'UNKNOWN'
|
||||||
|
|
||||||
@@ -72,9 +151,9 @@ pipeline {
|
|||||||
sh(returnStatus: true, script: """
|
sh(returnStatus: true, script: """
|
||||||
set +e
|
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"
|
echo "No TG-* reference found"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@@ -98,8 +177,7 @@ headers = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def get_json(path):
|
def get_json(path):
|
||||||
url = f"{taiga_url}{path}"
|
req = urllib.request.Request(f"{taiga_url}{path}", headers=headers)
|
||||||
req = urllib.request.Request(url, headers=headers)
|
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(req) as r:
|
with urllib.request.urlopen(req) as r:
|
||||||
return json.loads(r.read().decode("utf-8"))
|
return json.loads(r.read().decode("utf-8"))
|
||||||
@@ -136,9 +214,8 @@ payload = json.dumps({
|
|||||||
"version": data["version"],
|
"version": data["version"],
|
||||||
}).encode("utf-8")
|
}).encode("utf-8")
|
||||||
|
|
||||||
url = f"{taiga_url}/api/v1/{endpoint}/{data['id']}"
|
|
||||||
req = urllib.request.Request(
|
req = urllib.request.Request(
|
||||||
url,
|
f"{taiga_url}/api/v1/{endpoint}/{data['id']}",
|
||||||
data=payload,
|
data=payload,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
method="PATCH",
|
method="PATCH",
|
||||||
|
|||||||
Reference in New Issue
Block a user