0

我遇到了在我的 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
4

1 回答 1

0

我花了一段时间才发现的解决方案是使用 GitSCM 插件 DSL 类和方法来公开 MBP 作业配置中定义的 git url 和分支。这两个对象允许您在 checkout 函数调用中使用 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]]
])
于 2020-08-06T12:02:28.653 回答