<@ULVA73B9P> how do i create a pull step to retrie...
# ask-marvin
k
@Marvin how do i create a pull step to retrieve a git repository from azure devops
m
To help you with creating a pull step to retrieve a Git repository from Azure DevOps using Prefect, I need to determine which version of Prefect you're using. Let me provide guidance for both versions 2.x and 3.x, and we can refine it further once the version is clarified. ### Prefect 2.x 1. Install Required Packages: Ensure you have
gitpython
installed, as it can help you interact with Git repositories. 2. Create a Prefect Task: Define a task in your Prefect flow that uses
gitpython
or subprocess to clone the repository.
Copy code
python
from prefect import flow, task
import subprocess

@task
def clone_repo():
    repo_url = "<https://dev.azure.com/YourOrganization/_git/YourRepository>"
    subprocess.run(["git", "clone", repo_url])

@flow
def my_flow():
    clone_repo()

my_flow()
### Prefect 3.x 1. Install Required Packages: The steps for installation remain the same as in Prefect 2.x. 2. Create a Prefect Flow with a Pull Step: Define a flow that includes a step for cloning the repository.
Copy code
python
from prefect import flow, task
import subprocess

@task
def clone_repo():
    repo_url = "<https://dev.azure.com/YourOrganization/_git/YourRepository>"
    subprocess.run(["git", "clone", repo_url])

@flow
def my_flow():
    clone_repo()

my_flow()
In both examples, replace
"<https://dev.azure.com/YourOrganization/_git/YourRepository>"
with the actual URL of your Azure DevOps repository. Make sure you have the necessary permissions and authentication set up to access the repository. If you need any more detailed help or additional configuration like authentication methods, specifying branches, etc., please let me know the version of Prefect you are using, and I can refine my answer further.
n
🙅
hmm im not familiar w azure devops, but is it "git-compatible" like gitlab or bitbucket?
i.e. can you
git clone
it?
k
I could in prefect 2 by using a url including the personal access token
n
can you show me how you did that?
i think you'll want something like this
Copy code
from prefect import flow
from prefect.runner.storage import GitRepository


if __name__ == "__main__":
    flow.from_source(
        source=GitRepository(
            url="<https://github.com/me/myrepo.git>",
            credentials={"username": "oauth2", "access_token": "my-access-token"},
        ),
        entrypoint="example.py:my_flow"
    ).deploy(
        name="my-deployment",
        parameters=dict(name="Marvin"),
        work_pool_name="local", # or the name of your work pool
    )
k
Yeah, deployment command was
prefect deployment build src/flows/airbyte.py:airbyte_syncs -n airbyte-deployment -sb github/git-storage --work-queue prod
n
or instead if you want the yaml / CLI based thing you can do https://github.com/zzstoatzz/prefect-pack/blob/main/prefect.yaml#L9-L11 and
prefect --no-prompt deploy --all
k
I had setup a github repo storage block of type github_block with a url in the format https://PATTOKEN@organization.visualstudio.com/project/_git/prefect
n
yep it should also accept the
Block
you have now instead of the
GitRepository
class in the example
"it" being `from_source`'s
source
kwarg
k
I tried creating a new GitHub repository block as the old block says it is deprecated, is there a way I can use it?
Thanks for the help
n
in general we moved "integration-ish" code out of prefect core and into their respective integration library, so in this case that block has been superseded by this one so easiest way forward imo is just go copy your values from the old block into this type of block and then use that
k
Ok thanks, I'll give it a go.