How to access private repo packages in flutter using ssh?
Asked Answered
S

3

23

I have private repo in github, and use it as a packages in my project. in pubspec.yaml i write it like these.

dependencies:
  shared_preferences: ^0.4.3
  atomic_app_customer_musteat_id:
    git: [email protected]:organization/my_github_repo_ssh .git
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

but then the error is "Could not find a file named "pubspec.yaml" in my github_repo"

I have added ssh in my account, and trying to configuring machine user in github. Then I tried to change it to normal https link, and no errors. but when I tried build on ci/cd in bitrise and get error.

pub get failed (69) -- attempting retry 5 in 16 seconds...
Git error. Command: git fetch
fatal: not a git repository 

But still can't figure it out how to solve this issue.

Samovar answered 7/2, 2019 at 2:15 Comment(1)
I would like to ask how did you create the package? Was it with --template=package, or is it a simple project?Planksheer
P
4

I believe that the most elegant solution, especially for ci/cd pipelines and for teams working with Macos and linux machines, is using the .netrc file for the autologin process.

  1. Get a gitlab/github token with read access
  2. Run the script below with the appropriate env values on your Machine or Build Machine
#!/bin/bash

# Specify the credentials 
MACHINE="gitlab.com" #gitlab.com or github.com
LOGIN="[email protected]" #your email account on github/gitlab
PASSWORD="token"

# Create the .netrc file with the specified contents 
cat <<EOF > ~/.netrc 
machine $MACHINE 
login $LOGIN 
password $PASSWORD 
EOF

# Set permissions to ensure only the user can read and write the file 
chmod 600 ~/.netrc

Then on your pubspec.yaml just reference the package with https

dependencies:
  my_package:
    git:
      url: https://gitlab.com/team/my_package.git
      ref: 'myref'
Piliform answered 2/4 at 15:37 Comment(0)
G
29

Use the url line like this:

dependencies:
  my_project:
    git:
      url: ssh://git@gitserver/path/my_project.git
Gaye answered 7/2, 2019 at 2:23 Comment(3)
Thanks! I missed the ssh part, I think flutter should add this to their documentation.Samovar
More details about things like named commits etc hereGaye
what in about CI/CD eg github action?Wastrel
P
4

I believe that the most elegant solution, especially for ci/cd pipelines and for teams working with Macos and linux machines, is using the .netrc file for the autologin process.

  1. Get a gitlab/github token with read access
  2. Run the script below with the appropriate env values on your Machine or Build Machine
#!/bin/bash

# Specify the credentials 
MACHINE="gitlab.com" #gitlab.com or github.com
LOGIN="[email protected]" #your email account on github/gitlab
PASSWORD="token"

# Create the .netrc file with the specified contents 
cat <<EOF > ~/.netrc 
machine $MACHINE 
login $LOGIN 
password $PASSWORD 
EOF

# Set permissions to ensure only the user can read and write the file 
chmod 600 ~/.netrc

Then on your pubspec.yaml just reference the package with https

dependencies:
  my_package:
    git:
      url: https://gitlab.com/team/my_package.git
      ref: 'myref'
Piliform answered 2/4 at 15:37 Comment(0)
H
3

Use this format and you don't need to add ssh in front

dependencies:
<module_name>:
  git:
    url: [email protected]:<username>/Project.git

Please make sure you have configured the ssh-agent correctly.

Heartily answered 14/9, 2021 at 8:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.