PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 9, 2022

[FIXED] How to fetch entire repository with GitLab CI/CD?

 October 09, 2022     continuous-integration, git, gitlab, gitlab-ci     No comments   

Issue

I'm currently setting up GitLab CI/CD. We use GitVersion in our project, which throws the following error:

/root/.nuget/packages/gitversiontask/5.3.7/build/GitVersionTask.targets(46,9): error : InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely.

According to this blog this happens, when the CI-server does not fetch the full repository (we have both a develop and a master branch, but I'm working on a different one). For Jenkins we solved this problem by expanding the checkout stage:

stage("Checkout") { gitlabCommitStatus(name: "Checkout") {
    
    // These are the normal checkout instructions
    cleanWs()
    checkout scm
    
    // This is the additional checkout to get all branches
    checkout([
      $class: 'GitSCM',
      branches: [[name: 'refs/heads/'+env.BRANCH_NAME]],
      extensions: [[$class: 'CloneOption', noTags: false, shallow: false, depth: 0, reference: '']],
      userRemoteConfigs: scm.userRemoteConfigs,
    ])

    sh "git checkout ${env.BRANCH_NAME}"
    sh "git reset --hard origin/${env.BRANCH_NAME}"
}}

I'm essentially looking for something equivalent to this for the .gitlab-ci.yml file.


Solution

By default, runners download your code with a 'fetch' rather than a 'clone' for speed's sake, but it can be configured a number of ways. If you want all jobs in your project's pipeline to be cloned rather than fetched, you can change the default in your CI Settings:

settings bar enter image description here

If you don't want all your jobs to clone since it's slower, you can change it in your .gitlab-ci.yml for your job:

my_job:
  stage: deploy
  variables:
    GIT_STRATEGY: clone
  script:
    - ./deploy

You can read more about the GIT_STRATEGY variable here: https://docs.gitlab.com/ee/ci/runners/configure_runners.html#git-strategy

Note: You can also set this variable to none, which is useful if you don't need the code but maybe an artifact created by a previous job. Using this, it won't checkout any code, but skip straight to your script.



Answered By - Adam Marshall
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing