forvaidya's answer didn't work for me (though it is now 4 years later).
(Relative URLs in .gitmodules
are resolved to full URLs in .git/config
by git submodule sync
.)
persistCredentials: true
will keep the authorization header available in git config
for future steps, but it is keyed by your main repo URL. As long as the submodule repo(s) are in the same organization, you can reuse the header, though - e.g. in a pipeline Powershell script:
steps:
- checkout: self
submodules: false
persistCredentials : true
- powershell: |
$header = $(git config --get-all http.$(Build.Repository.Uri).extraheader)
git -c http.extraheader="$header" submodule sync
git -c http.extraheader="$header" submodule update --init --force --depth=1
(I gleaned these details from the logs of the standard checkout
step. Note the reference to the Build.Repository.Uri
pipeline variable.)
The above will accomplish a full ("unshallow") checkout of the main repo (useful for e.g. GitVersion), without submodules, and a shallow checkout of any submodules.
Edit: The documented way to get the authorization header is
$header = "AUTHORIZATION: bearer $(System.AccessToken)"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…