我在jenkins中有一个Github组织
项目。在我的代码库根目录下,我的Jenkinsfile
看起来像这样:
node {
def jenkinsCredsId = 'xxxxxxxx-yyyy-zzzz-aaaa-bbbbbbbbbbbb'
stage 'Checkout'
checkout scm
// I also tried the following:
// checkout scm: [$class: 'GitSCM', source: 'ssh://git@github.com:MY_ORGANISATION/jenkins-testing-temp.git', clean: true, credentialsId: jenkinsCredsId]
stage 'Build'
// generate some artefact (dist.zip)
stage 'Release'
sshagent([jenkinsCredsId]) {
sh '''
git remote -v // show remotes
ssh-add -l // show currently loaded ssh keys fingerprints
git fetch --all --tags // IT FAILS HERE
CURRENT_BUILD_TAG="some_build/${BUILD_NUMBER}"
git tag ${CURRENT_BUILD_TAG}
git push --tags
github-release release \
--security-token ${GITHUB_RELEASE_TOKEN} \
--user MY_ORGANIZATION \
--repo MY_REPO \
--tag ${CURRENT_BUILD_TAG} \
--name ${CURRENT_BUILD_TAG}
github-release upload \
--security-token ${GITHUB_RELEASE_TOKEN} \
--user MY_ORGANIZATION \
--repo MY_REPO \
--tag ${CURRENT_BUILD_TAG} \
--name ${CURRENT_BUILD_TAG} \
--file dist.zip
'''
}
这里有几行代码用于测试仓库访问,但 在
git fetch
部分出现错误,错误信息如下:
从上面的fatal: could not read Username for 'https://github.com': No such device or address
Jenkinsfile
中运行 git remote -v
命令会输出类似于 origin https://github.com/MY_ORGANIZATION/MY_REPO
的内容。我的
Github 组织
git 配置如下:
![repository-sources-github-organization-jenkins-config](https://istack.dev59.com/VP96Y.webp)