Build an Image from a Different Git Repository

Using this repository we’ll help you figure out with properties of git-clone step.

Looking around

In the root of this repository you’ll find a file named codefresh.yml, this is our build descriptor and it describes the different steps that comprise our process. Let’s quickly review the contents of this file:

codefresh.yml

version: '1.0'
steps:
  clone_a_repo:
    type: git-clone
    repo: https://github.com/${{REPO_OWNER}}/${{REPO_NAME}}.git
    credentials:
      username: ${{GITHUB_USERNAME}}
      password: ${{GITHUB_PASSWORD}}
  
  build_the_image:
    type: build
    working-directory: ${{clone_a_repo}}
    image-name: myuser/myservice
    tag: ${{CF_BRANCH}}
Example

Just head over to the example repository in Github and follow the instructions there.

Using This Example

To use this example:

  • Fork this repository to your own [INSERT_SCM_SYSTEM (git, bitbucket)] account.
  • Log in to Codefresh using your [INSERT_SCM_SYSTEM (git, bitbucket)] account.
  • Click the Add Service button.
  • Select the forked repository.
  • Select the I have a Codefresh.yml file option.
  • Complete the wizard.
  • Rejoice!

Git-clone step with github token

How to generate the github token

Go to the page Personal access tokens Generate and configure the access for personal token Configuration in Codefresh:

We assume you already forked this repo and create a service for it

  1. Open the service and add new pipeline
  2. Switch to Use YML build
  3. Change the YML File Location to be ./codefresh.git.clone.example.yml
  4. Under Environment variables fill the next variables:
    • GIT_TOKEN your personal access token that you generated on github
    • REPO_OWNER owner of repository that you want to clone
    • REPO_NAME name of repository that you want to clone
    • BRANCH branch of repo

codefresh.yml

git_clone:
    type: git-clone
    description: "Step description"
    repo: https://${{GIT_TOKEN}}@github.com/${{REPO_OWNER}}/${{REPO_NAME}}.git
    revision: ${{BRANCH}}

Instead of hard-coding the credentials, you can provide the environment variables

git-clone-pipeline.png