+add jenkinsfile

This commit is contained in:
dmit.b
2026-05-16 11:05:29 +03:00
parent 69f3d09e62
commit 78a4a160ad
Vendored
+197
View File
@@ -0,0 +1,197 @@
pipeline {
agent any
environment {
FLUTTER_VERSION = '3.27.4'
JAVA_VERSION = '17'
ANDROID_BUILD_DIR = 'build'
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
disableConcurrentBuilds()
timeout(time: 60, unit: 'MINUTES')
timestamps()
}
parameters {
string(name: 'BUILD_TYPE', value: 'all', description: 'Build type: all, android, web')
string(name: 'ANDROID_FLAVOR', value: 'release', description: 'Android build: debug, release')
string(name: 'VERSION_NAME', value: '', description: 'Override version name (optional)')
string(name: 'VERSION_CODE', value: '', description: 'Override version code (optional)')
booleanParam(name: 'CLEAN_BUILD', value: true, description: 'Run flutter clean before build')
}
triggers {
pollSCM('H 2 * * *')
}
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 = tool name: 'Flutter', type: 'flutter'
env.PATH = "${flutterHome}/bin:${env.PATH}"
sh 'flutter doctor -v'
}
}
}
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('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 "flutter build web --release${extraArgs}"
}
}
post {
success {
archiveArtifacts artifacts: "build/web/**/*", fingerprint: true
}
}
}
}
post {
always {
cleanWs()
}
success {
echo 'Build completed successfully!'
}
failure {
echo 'Build failed!'
}
}
}