git - Jenkins Pipeline Git Push 通过 Windows 代理节点
问题描述
所以我有以下场景:
Jenkins 主节点:Red Hat 7 Jenkins 代理节点:Windows Server 2019
使用 Windows 代理节点,我正在尝试签出存储库、添加/更新更改以及提交并推送回 GitHub。
我签出并提交正常工作,但在推回 GitHub 时遇到问题。我尝试了一些方法,但似乎都没有。
管道:
def NodeLabel = 'windows'
//def CustomWorkSpace = "C:/JenkinsWorkspace/${env.JOB_BASE_NAME}"
def CustomWorkSpace = "C:/Work"
// Organization
def OrganizationName = [
'organization1',
'organization2'
]
// Solution
def SolutionMap = [
SolutionA: [
SolutionName: 'SolutionA',
RequiredVersion: '1.0.0.0',
UnpackedFileFolder: 'FolderA/ConfigurationA/SolutionA'
]
]
pipeline {
agent {
node {
<Node Stuff...>
}
}
environment {
RELEASE_NAME = 'Release-0'
SOURCE_DIRECTORY = 'Source'
}
parameters {
<Parameter...>
}
stages {
// Check Out Repository
stage('Check Out Repository') {
steps {
checkout([
$class: 'GitSCM',
branches: [
[name: '*/development']
],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'RelativeTargetDirectory',
relativeTargetDir: SOURCE_DIRECTORY],
[$class: 'LocalBranch',
localBranch: RELEASE_NAME],
[$class: 'UserIdentity',
email: '<Email>',
name: '<Name>'],
[$class: 'CleanBeforeCheckout',
deleteUntrackedNestedRepositories: true]
],
submoduleCfg: [],
userRemoteConfigs: [
[credentialsId: '<Credential>',
url: '<URL>']
]
])
}
}
// Solution
stage('Solution') {
steps {
script {
SolutionMap.each { Solution ->
<Some Work...>
// Git Commit Solution Source Code
stage("Git Commit Solution: ${Solution.key}") {
dir(SOURCE_DIRECTORY) {
powershell(script: """
git config core.fileMode false
git config core.autocrlf false
git add --all
git commit --allow-empty --message="Commit ${Solution.value.SolutionName} version ${Solution.value.RequiredVersion}"
""")
}
}
}
}
}
}
// Git
stage('Git Push') {
steps {
dir(SOURCE_DIRECTORY) {
powershell(script: """
Write-Host User Profile: ${USERPROFILE}
Write-Host Release Name: ${RELEASE_NAME}
git push origin ${RELEASE_NAME}
""")
}
}
}
}
}
我尝试了几件事:
如果我只是尝试
git push origin ${RELEASE_NAME}
或者
powershell(script: """ssh-add ${USERPROFILE}/.ssh/id_rsa""")
powershell(script: """git push origin ${RELEASE_NAME}""")
我会得到:
powershell.exe : Could not create directory '/work/jenkins/latest/.ssh'.
At C:\Work\Source@tmp\durable-cfdcf986\powershellWrapper.ps1:3 char:1
+ & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Could not creat...s/latest/.ssh'.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
如果我要尝试 subshell 方法:
ssh-agent bash -c 'ssh-add ${USERPROFILE}/.ssh/id_rsa; git push origin ${RELEASE_NAME}'
它执行,但似乎没有做任何事情或推动任何事情。
任何帮助,将不胜感激。
解决方案
推荐阅读
- python - 获取错误 datetime.date(2018, 6, 12) 在 Python 中不是 JSON 可序列化的
- vba - 在 PowerPoint 中绘制涂鸦形状
- css - 百里香叶 3 弹簧 5 负载 css
- reactjs - React Virtualized Masonry 不使用浏览器调整大小
- c++ - 通过 std::sort 对 C 2D 数组进行排序
- windows - 平板模式下 Windows 10 上的 Python/PyQt5 全屏应用程序
- python - 深度图像球检测
- java - 如何从 sql 日期中获取日期顺序和日期组?
- c - 预处理器包括路径、宏等条目不可用
- amazon-web-services - 从存储桶策略中排除一个 Amazon S3 对象