【发布时间】:2020-06-09 08:38:23
【问题描述】:
是否有一个选项可以像证书一样向 git-login-process 添加更多登录信息? 据我所知,配置中只有基本凭据是可能的。
是否有机会添加一些进一步的配置?也许是azure-pipelines.yml?
【问题讨论】:
-
请问这个状态怎么样?以下方法对您有帮助吗?如果您仍有疑问或疑问,请随时发表评论。
标签: azure-devops azure-pipelines
是否有一个选项可以像证书一样向 git-login-process 添加更多登录信息? 据我所知,配置中只有基本凭据是可能的。
是否有机会添加一些进一步的配置?也许是azure-pipelines.yml?
【问题讨论】:
标签: azure-devops azure-pipelines
通过以下方式解决了:
为克隆作业创建了一个模板文件:
parameters:
- name: RepoUrl
type: string
- name: cloneIntoDir
type: string
steps:
- task: DownloadSecureFile@1
name: cainfo
displayName: 'Download cainfo'
inputs:
secureFile: 'cainfo.cert'
- task: DownloadSecureFile@1
name: cert
displayName: 'Download cert.crt'
inputs:
secureFile: 'cert.crt'
- task: DownloadSecureFile@1
name: keypem
displayName: 'Download key.pem'
inputs:
secureFile: 'key.pem'
- script: mkdir ${{ parameters.cloneIntoDir }}
displayName: creating directory ${{ parameters.cloneIntoDir }}
- script: |
cd ${{ parameters.cloneIntoDir }}
git config --global http.sslCAInfo "$(cainfo.secureFilePath)"
git config --global http.sslCert "$(cert.secureFilePath)"
git config --global http.sslKey "$(keypem.secureFilePath)"
git clone https://$(User):$(Password)@${{ parameters.RepoUrl }} .
此模板对从管道库下载的文件执行所有 git-magic。
在 build-yml 中使用了模板文件
trigger: none
strategy:
matrix:
linux:
imageName: 'ubuntu-latest'
windows:
imageName: 'windows-2019'
pool:
vmImage: $(imageName)
variables:
- group: Credentials
steps:
- template: ../templates/clone-repo-template.yml
parameters:
RepoUrl: 'www.repos_url.com/project.git'
cloneIntoDir: 'myRepoDir'
此处重要:凭据的变量组必须包含在该文件中,尽管仅在模板中需要凭据(原因:变量不能在步骤中定位)
到那时它就完成了,您的仓库中的代码现在位于myRepoDir。您可以在步骤 2 中使用您的特定构建命令扩展该文件。
但是您可以更进一步:可能您希望将 build-yml 集成到您的存储库中,并且开发人员活动可能无法访问 azure-repo 但应该能够编辑 build-yml。为此:
创建另一个模板
parameters:
- name: RepoUrl
type: string
- name: copyScript
type: string
jobs:
- job: SyncRepos
pool:
vmImage: 'ubuntu-latest'
variables:
- name: remoteRepoDir
value: 'DirectoryToCloneInto'
- group: Credentials
steps:
- template: ../templates/clone-repo-template.yml
parameters:
RepoUrl: ${{ parameters.RepoUrl }}
cloneIntoDir: $(remoteRepoDir)
- script: 'git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" clone $(Build.Repository.Uri)'
displayName: 'Clone Azure-Repo $(Build.Repository.Uri)'
- script: |
cd '$(Build.Repository.Name)'
${{ parameters.copyScript }}
displayName: 'Copy file to direcorty $(Build.Repository.Name)'
- script: |
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
displayName: 'Configure Git for commit'
- script: |
cd '$(Build.Repository.Name)'
git add -A
git commit -m "auto commit from azure sync"
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push
displayName: 'push changes'
如您所见,此模板也使用了步骤 1 中的模板
trigger: none
jobs:
- template: ../templates/sync-repo-files-template.yml
parameters:
copyScript: |
cp -f ../$(remoteRepoDir)/azure-pipeline.yml .
RepoUrl: 'www.repos_url.com/project.git'
在管道中运行该 yml 将克隆您的 repo,克隆 azure-repo,将 azure-pipeline.yml-file 从您的 repo 复制到 azure repo,存储、提交和推送。
您只需确保Build Service-user 也有权为您的 repo 做出贡献:
最后你可以: * 在您的私人仓库中编辑 azure 管道文件,提交 + 推送 * 让第 4 步中的同步管道运行 * 之后 azure repo 包含更新的管道文件 * 您可以在更新后的文件上运行您的构建作业
【讨论】:
在构建管道的Get source步骤中,SSL是其中的默认选项。
所以,这里有两种方法你可以考虑。
方法一:
1) 将 SSL 证书存储到 Azure Key Vault。
2) 然后将此 Azure Key Vault 源连接到变量组。
3) 涉及此变量组并包括 azure 密钥库。
对于上述内容,blog 中描述了详细的步骤。你可以检查一下。
现在,在 azure devops 中,我们添加一个内置步骤 Azure Key Vault 任务,同时您启用 Azure 密钥保管库并将其链接到管道。此外,此内置步骤在 Get sources 步骤之前执行。所以,这个时候,证书就可以被Get sources正确的安装和使用了。
方法二:
另一种方法是,您配置一个自我代理并在您的构建机器中运行commands:
git config --global http.sslBackend schannel
git config --global http.sslCAPath <the path/to/your/certificate.crt>
【讨论】:
Ensure that the user has 'Owner' or 'User Access Administrator' permissions on the Subscription。在方法 2 中——据我所知——我要么需要一个单独的预配置 VM,要么使用位于例如的初始 azure-pipelines.yml。在管道的 repo 中,然后从然后启动的vmImage: 'windows-2019'-VM 中执行 git pull。对吗?
vmImage: 'windows-2019' 这用于 YAML 管道,它是与托管代理一起运行的架构。正如我所说,在这里您可以使用自我代理。此时,无法使用。您应该将该架构替换为 pool: {pool name} 。看到这个:docs.microsoft.com/en-us/azure/devops/pipelines/…
yml-文件开头,必须放在存储库中。因此,该作业必须能够在作业运行的第一步中访问该存储库。换句话说:在第二种解决方案中,我无法将我的yml 文件放入私有存储库中,因为作业无法通过在 azure devpos 前端中配置的直接方式访问它。对吗?