Created
July 4, 2020 06:45
-
-
Save amitsingh-007/b83297e3d6993cf2a1f907f5396da0aa to your computer and use it in GitHub Desktop.
Fetching base branch on CI as well as on local machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Need to add refs and then fetch, as Jenkins does not allow to fetch other barnches | |
*/ | |
async function fetchBaseBranch(baseBranch) { | |
try { | |
console.log("Fetching ${baseBranch} from remote"); | |
const addBaseRefs = `git config --add remote.origin.fetch +refs/heads/${baseBranch}:refs/remotes/origin/${baseBranch}`; | |
const fetchBase = `git fetch --no-tags origin +refs/heads/${baseBranch}:refs/remotes/origin/${baseBranch}`; | |
const command = `${addBaseRefs} && ${fetchBase}`; | |
await exec(command); | |
} catch (ex) { | |
console.log("Failed in fetching changed files", ex); | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment