For a project, I would like to setup Jenkins so that it can automatically push my Flutter package to pub.dev. So far I have followed the steps on the official Dart documentation and setup a Google Cloud service account which is allowed to publish my package (set in the package settings on pub.dev), and a key belonging to this account.
I do not want to test the setup by calling dart pub publish and having it publish to pub.dev immediately, instead I first want to verify that it is able to connect to pub.dev and its corresponding package. Is this possible by using dart pub login? When I attempt it now, it says I need to authenticate my account by clicking on a link, which defeats the purpose of it being an automatic publish job.
Is it even possible to use dart pub login with using a Google Cloud services account, or is only dart pub publish supported? What other command could I try to verify the connection works?
My Jenkins file currently has this stage:
stage('authenticate google service account') {
steps {
withCredentials([file(credentialsId: 'google-service-account', variable:
'GOOGLE_CLOUD_KEY_FILE')]) {
script {
sh """
gcloud auth activate-service-account --key-file=${GOOGLE_CLOUD_KEY_FILE}
gcloud auth print-identity-token \
--audiences=https://pub.dev \
| dart pub token add https://pub.dev/packages/package_name
dart pub login
"""
}
}
}
}
You can try this code: