Files
geo_front/Jenkinsfile
T

216 lines
7.9 KiB
Groovy

pipeline {
agent any
environment {
FLUTTER_VERSION = '3.27.4'
JAVA_VERSION = '17'
ANDROID_BUILD_DIR = 'build'
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
disableConcurrentBuilds()
timeout(time: 1, unit: 'MINUTES')
timestamps()
}
parameters {
string(name: 'BUILD_TYPE', defaultValue: 'all', description: 'Build type: all, android, web')
string(name: 'ANDROID_FLAVOR', defaultValue: 'release', description: 'Android build: debug, release')
string(name: 'VERSION_NAME', defaultValue: '', description: 'Override version name (optional)')
string(name: 'VERSION_CODE', defaultValue: '', description: 'Override version code (optional)')
booleanParam(name: 'CLEAN_BUILD', defaultValue: true, description: 'Run flutter clean before build')
}
stages {
stage('Preparation -)') {
steps {
script {
def buildType = params.BUILD_TYPE.toLowerCase()
if (buildType == 'all' || buildType == 'android') {
currentBuild.description = "Android ${params.ANDROID_FLAVOR}"
} else if (buildType == 'web') {
currentBuild.description = "Web"
} else {
error("Unknown BUILD_TYPE: ${buildType}. Use 'all', 'android', or 'web'")
}
}
}
}
stage('Environment Setup') {
steps {
script {
def flutterHome = "/opt/flutter"
env.PATH = "${flutterHome}/bin:${env.PATH}"
sh 'flutter doctor -v'
}
script {
//def ANDROID_HOME = "/opt/flutter"
//env.PATH = "${flutterHome}/bin:${env.PATH}"
//sh 'find /soft -name "*droid*"'
}
}
}
stage('Flutter Deps') {
when {
expression {
params.CLEAN_BUILD == true
}
}
steps {
sh 'flutter clean'
}
}
stage('Install Dependencies') {
steps {
sh 'flutter pub get'
}
}
stage('Analyze & Lint') {
steps {
sh 'flutter analyze --no-fatal-infos'
}
}
stage('Tests') {
steps {
sh 'flutter test --concurrency=1'
}
post {
always {
junit allowEmptyResults: true, testResults: '**/test-results/*.xml'
}
}
}
// stage('Build Android') {
// when {
// expression {
// def buildType = params.BUILD_TYPE.toLowerCase()
// buildType == 'all' || buildType == 'android'
// }
// }
// stages {
// stage('Build APK Debug') {
// when {
// expression { params.ANDROID_FLAVOR.toLowerCase() == 'debug' }
// }
// steps {
// script {
// def buildName = "debug"
// if (params.VERSION_NAME) buildName += "-${params.VERSION_NAME}"
// if (params.VERSION_CODE) buildName += "-${params.VERSION_CODE}"
// currentBuild.displayName = "#${currentBuild.number} - Android ${buildName}"
// def extraArgs = ''
// if (params.VERSION_NAME) extraArgs += " --build-name=${params.VERSION_NAME}"
// if (params.VERSION_CODE) extraArgs += " --build-number=${params.VERSION_CODE}"
// sh "flutter build apk --${buildName}${extraArgs}"
// }
// }
// post {
// success {
// archiveArtifacts artifacts: "build/app/outputs/flutter-apk/app-${buildName}.apk", fingerprint: true
// archiveArtifacts artifacts: "build/app/outputs/flutter-apk/*.apk", fingerprint: true
// }
// }
// }
// stage('Build APK Release') {
// when {
// expression { params.ANDROID_FLAVOR.toLowerCase() == 'release' }
// }
// steps {
// script {
// def buildName = "release"
// if (params.VERSION_NAME) buildName += "-${params.VERSION_NAME}"
// if (params.VERSION_CODE) buildName += "-${params.VERSION_CODE}"
// currentBuild.displayName = "#${currentBuild.number} - Android ${buildName}"
// def extraArgs = ''
// if (params.VERSION_NAME) extraArgs += " --build-name=${params.VERSION_NAME}"
// if (params.VERSION_CODE) extraArgs += " --build-number=${params.VERSION_CODE}"
// sh "flutter build apk --release${extraArgs}"
// }
// }
// post {
// success {
// archiveArtifacts artifacts: "build/app/outputs/flutter-apk/*.apk", fingerprint: true
// }
// }
// }
// stage('Build AAB Release') {
// when {
// expression { params.ANDROID_FLAVOR.toLowerCase() == 'release' }
// }
// steps {
// script {
// def extraArgs = ''
// if (params.VERSION_NAME) extraArgs += " --build-name=${params.VERSION_NAME}"
// if (params.VERSION_CODE) extraArgs += " --build-number=${params.VERSION_CODE}"
// sh "flutter build appbundle --release${extraArgs}"
// }
// }
// post {
// success {
// archiveArtifacts artifacts: "build/app/outputs/bundle/release/*.aab", fingerprint: true
// }
// }
// }
// }
// }
stage('Build Web') {
when {
expression {
def buildType = params.BUILD_TYPE.toLowerCase()
buildType == 'all' || buildType == 'web'
}
}
steps {
script {
currentBuild.displayName = "#${currentBuild.number} - Web"
def extraArgs = ''
if (params.VERSION_NAME) extraArgs += " --build-name=${params.VERSION_NAME}"
if (params.VERSION_CODE) extraArgs += " --build-number=${params.VERSION_CODE}"
sh "rm -f web.zip"
sh "flutter build web --release${extraArgs}"
sh "cd build/web && zip -r ../../web.zip *"
archiveArtifacts 'web.zip'
sh "rm -f web.zip"
}
}
post {
success {
sh "cd build/web && zip -r ../../web.zip *"
archiveArtifacts 'web.zip'
sh "rm -f web.zip"
// archiveArtifacts artifacts: "build/web/**/*", fingerprint: true
}
}
}
}
post {
always {
cleanWs()
}
success {
echo 'Build completed successfully!'
}
failure {
echo 'Build failed!'
}
}
}