7

I have private dependency from GitLab in my Flutter mobile app project. It is specified in pubspec.yaml with git repository link and I can successfully run pub get if I use ssh for it (I have generated ssh key and add it to my gitlab account)

  my_private_package:
    git:
      url: ssh://git@************/my_private_package.git

Now I want to build my app with AppCenter and deploy to stores. It is not possible to use ssh keys on AppCenter build phase, so the only working solution I see is to use GitLab Deploy Token as environment variable to access my private package from AppCenter machine. Git link to access the repository becomes this:

  my_private_package:
    git:
      url: https://gitlab+deploy-token-1:${DEPLOY_TOKEN}@************/my_private_package.git

Now, as far as I understand, pubspec can't resolve DEPLOY_TOKEN environment variable this way. pub get completes with error:

Git error. Command: `git clone --mirror https://gitlab+deploy-token-1:******@*******/my_private_package.git /Users/***/Library/flutter/.pub-cache/git/cache/my_private_package***`
stdout:                                                                 
stderr: Cloning into bare repository '/Users/***/Library/flutter/.pub-cache/git/cache/my_private_package***'...
remote: HTTP Basic: Access denied                                       
remote: You must use a personal access token with 'read_repository' or 'write_repository' scope for Git over HTTP.
remote: You can generate one at https://*****/-/profile/personal_access_tokens
fatal: Authentication failed for 'https://gitlab.*****/my_private_package.git/'
exit code: 128   

I also tried to use personal access tokens mentioned in error message above, but getting the same result. Although git clone https://gitlab+deploy-token-1:${DEPLOY_TOKEN}@*******/my_private_package.git from command line works fine if DEPLOY_TOKEN environment variable specified.

My question: Is it possible to use evnironment variables directly from pubspec.yaml? If no, how can I get my private package from another (not gitlab runner) CI machine?

Mol0ko
  • 2,938
  • 1
  • 18
  • 45
  • 1
    Some alternatives: generate your `pubspec.yaml` file, or use [`path` dependencies](https://dart.dev/tools/pub/dependencies#path-packages) with Git repositories that you fetch separately. – jamesdlin Mar 29 '21 at 19:54

1 Answers1

0

Currently it's not possible to set environment variables in pubspec.yaml as mentioned in this thread. As a workaround you can fetch the repository locally and configure it as a path package.

Omatt
  • 8,564
  • 2
  • 42
  • 144