我遇到了一个问题,即在我的MBP作业中检索主存储库之前检索共享库。在我的日常工作和自由式工作中,情况并非如此。由于Jenkinsfile共享库方法尝试从主存储库读取Xcode的版本,因此MBP作业失败,并显示以下错误。这是可以理解的,因为存储库还没有被签出。这在常规管道作业中工作得很好,在常规管道作业的日志中,我可以看到在共享库之前发生了轻量级的签出。在MBP中,有没有办法强制在共享库之前签出主存储库?
MultiBranchPipeline中的=出现故障:
Branch event
Obtained Fastlane/Jenkinsfile-pra-MAIN-VM.groovy from d0-obfuscated+18-obfuscated
Running in Durability level: MAX_SURVIVABILITY
Loading library vm-library@master
Attempting to resolve master from remote references...
> git --version # timeout=10
using GIT_ASKPASS to set credentials Bot for posting back to bitbucket PRs
> git ls-remote -- ssh://git@bitbucket.somecompany.org/mob/shared-library.git # timeout=10
Found match: refs/heads/master revision 46-obfuscated
using credential mobileci-bot
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url ssh://git@bitbucket.somecompany.org/mob/shared-library.git # timeout=10
Fetching without tags
Fetching upstream changes from ssh://git@bitbucket.somecompany.org/mob/shared-library.git
> git --version # timeout=10
using GIT_ASKPASS to set credentials Bot for posting back to bitbucket PRs
> git fetch --no-tags --progress -- ssh://git@bitbucket.somecompany.org/mob/shared-library.git +refs/heads/*:refs/remotes/origin/* # timeout=10
Checking out Revision 46-obfuscated (master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 46-obfuscated # timeout=10
Commit message: "Merge pull request #7 in MOB/shared-library from develop to master"
> git rev-list --no-walk 46-obfuscated # timeout=10
[Bitbucket] Notifying pull request build result=在常规管道中成功:
Checking out git ssh://git@bitbucket.somecompany.org/tp/mymobileapp.git into /Users/Shared/Development/Build/Jenkins/workspace/dev/username/mymobileapp/PRA/OJ-iOS-PRA@script to read Fastlane/Jenkinsfile-ios-pra.groovy
using credential BitBucketUser
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url ssh://git@bitbucket.somecompany.org/tp/mymobileapp.git # timeout=10
Fetching upstream changes from ssh://git@bitbucket.somecompany.org/tp/mymobileapp.git
> git --version # timeout=10
using GIT_ASKPASS to set credentials Bitbucket-cibuild
> git fetch --tags --progress -- ssh://git@bitbucket.somecompany.org/tp/mymobileapp.git +refs/heads/*:refs/remotes/origin/* # timeout=10
> git rev-parse origin/develop^{commit} # timeout=10
Checking out Revision d0-ofuscated (origin/develop)
> git config core.sparsecheckout # timeout=10
> git checkout -f d0-ofuscated # timeout=10
Commit message: "Merge pull request #19 in TP/mymobileapp from updateBuildTools to develop"
> git rev-list --no-walk c3-ofuscated # timeout=10
Running in Durability level: MAX_SURVIVABILITY
Loading library library@master
Attempting to resolve master from remote references...
> git --version # timeout=10
using GIT_SSH to set credentials Build-Agent
> git ls-remote -h -- ssh://git@bitbucket.somecompany.org/mob/shared-library.git # timeout=10
Found match: refs/heads/master revision 46-obfuscated
using credential Build-Agent
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url ssh://git@bitbucket.somecompany.org/mob/shared-library.git # timeout=10
Fetching without tags
Fetching upstream changes from ssh://git@bitbucket.somecompany.org/mob/shared-library.git
> git --version # timeout=10
using GIT_SSH to set credentials Build-Agent
> git fetch --no-tags --progress -- ssh://git@bitbucket.somecompany.org/mob/shared-library.git +refs/heads/*:refs/remotes/origin/* # timeout=10
Checking out Revision 46-obfuscated (master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 46-obfuscated # timeout=10
Commit message: "Merge pull request #7 in MOB/shared-library from develop to master"
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /Users/Shared/Development/Build/Jenkins/workspace/dev/username/mymobileapp/PRA/OJ-iOS-PRA
[Pipeline] {
[Pipeline] pwd
[Pipeline] sh
+ grep -Eo '[^XCODE_VERSION=]*"[0-9.]+"' /Users/Shared/Development/Build/Jenkins/workspace/dev/username/mymobileapp/PRA/OJ-iOS-PRA@script/Fastlane/.env.default
[Pipeline] sh
+ cat /Users/Shared/Development/Build/tools/agent-selection/xcode_versions.json发布于 2020-08-06 20:02:29
我花了一段时间才发现的解决方案是使用MBP plugin DSL类和方法来公开GitSCM作业配置中定义的git url和分支。这两个对象允许您在签出函数调用中使用GitSCM稀疏签出,并指定特定的文件或文件目录。不需要curl或wget或凭证插值。精确的命令语法如下:
此代码允许您签出共享库中的单个文件,该库包含在配置的作业的Jenkinsfile中的节点块之前调用的代码。
def scmUrl = scm.getUserRemoteConfigs()[0].getUrl()
def branch = scm.getBranches()
checkout ([
$class:'GitSCM',
branches: branch,
doGenerateSubmoduleConfigurations: false,
extensions: [
[
$class: 'SparseCheckoutPaths',
sparseCheckoutPaths: [[path: '/myDirectory/singlefile.txt']]
]
],
submoduleCfg:[],
userRemoteConfigs: [[url:scmUrl]]
])https://stackoverflow.com/questions/62767331
复制相似问题