Home > Software engineering >  Can't run flutter build from Jenkins
Can't run flutter build from Jenkins

Time:04-20

I tried to run a flutter build from jenkins using the following pipeline code :

pipeline {
    agent any

    stages {
        stage('build') {
            steps {
                bat 'C:\\path_to_doc\\flutter_dev\\flutter\\bin\\flutter.bat build web -t "C:\\path_to_doc\\lib\\src\\main\\main.dart"'
            }
        }
    }
    post{
        always {
            archiveArtifacts artifacts: 'C:\\path_to_doc\\build\\web\\index.html', fingerprint: true, followSymlinks: false
        }
    }
}

I got this error in jenkins :

enter image description here

I tried to write the flutter build code in a bat file in the root of my flutter project, and then execute this file on the pipeline code, got the same error.

What is the correct way to proceed to avoid this error ?

CodePudding user response:

Jenkins has a habit of reverting to the initial workspace directory for each separate command. Try setting the directory after your steps{ line:

dir('C:\\path_to_doc\\flutter_dev\\flutter\\bin\\') {
    bat 'flutter.bat build web -t "C:\\path_to_doc\\lib\\src\\main\\main.dart"'
}

This will ensure that your script will run in this location. So if your pubspec.yaml is in this location, it should be able to find it. In any case, this is a problem with the directory, so if this doesn't work, some manual debugging would be necessary to see what went wrong.

  • Related