Create a BitBucketRepository block for a public repo¶
fromprefect_bitbucketimportBitBucketRepositorypublic_repo="https://bitbucket.org/my-workspace/my-repository.git"# Creates a public BitBucket repository BitBucketRepository blockpublic_bitbucket_block=BitBucketRepository(repository=public_repo)# Saves the BitBucketRepository block to your Prefect workspace (in the Blocks tab)public_bitbucket_block.save("my-bitbucket-block")
Create a BitBucketRepository block for a public repo at a specific branch or tag¶
fromprefect_bitbucketimportBitBucketRepositorypublic_repo="https://bitbucket.org/my-workspace/my-repository.git"# Creates a public BitBucket repository BitBucketRepository blockbranch_bitbucket_block=BitBucketRepository(reference="my-branch-or-tag",# e.g "master"repository=public_repo)# Saves the BitBucketRepository block to your Prefect workspace (in the Blocks tab)branch_bitbucket_block.save("my-bitbucket-branch-block")
Create a new BitBucketCredentials block and a BitBucketRepository block for a private repo¶
fromprefect_bitbucketimportBitBucketCredentials,BitBucketRepository# For a private repo, we need credentials to access itbitbucket_credentials_block=BitBucketCredentials(token="my-token",username="my-username"# optional)# Saves the BitBucketCredentials block to your Prefect workspace (in the Blocks tab)bitbucket_credentials_block.save(name="my-bitbucket-credentials-block")# Creates a private BitBucket repository BitBucketRepository blockprivate_repo="https://bitbucket.org/my-workspace/my-repository.git"private_bitbucket_block=BitBucketRepository(repository=private_repo,bitbucket_credentials=bitbucket_credentials_block)# Saves the BitBucketRepository block to your Prefect workspace (in the Blocks tab)private_bitbucket_block.save(name="my-private-bitbucket-block")
Use a preexisting BitBucketCredentials block to create a BitBucketRepository block for a private repo¶
fromprefect_bitbucketimportBitBucketCredentials,BitBucketRepository# Loads a preexisting BitBucketCredentials blockBitBucketCredentials.load("my-bitbucket-credentials-block")# Creates a private BitBucket repository BitBucketRepository blockprivate_repo="https://bitbucket.org/my-workspace/my-repository.git"private_bitbucket_block=BitBucketRepository(repository=private_repo,bitbucket_credentials=bitbucket_credentials_block)# Saves the BitBucketRepository block to your Prefect workspace (in the Blocks tab)private_bitbucket_block.save(name="my-private-bitbucket-block")
Differences between Bitbucket Server and Bitbucket Cloud
For Bitbucket Cloud, only set the token to authenticate. For Bitbucket Server, set both the token and the username.