0

I am experiencing an issue where the shared library is retrieved before the main repository is retrieved in my MBP job. This was not the case in my regular pipeline and freestyle jobs. Because a Jenkinsfile shared library method attempts to read the version of Xcode from the main repository, the MBP jobs fails with the following error. Which is understandable because the repository has yet to be checked out. This works perfectly in a regular pipeline job and I can see the light checkout happen before the shared library in the logs of the regular pipeline job. Is there a way, in a MBP, to force the checkout of the main repository to occur before the shared library?

=========================================================================================== FAILING here in 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

=========================================================================================== SUCCEEDING Here in Regular Pipeline:

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
duncwa
  • 149
  • 1
  • 7

1 Answers1

0

The solution, which took me a while to discover is to use GitSCM plugin DSL classes and methods to expose the git url and branch defined in the MBP job configuration. These two objects allow you to use the GitSCM sparse checkout in the checkout function call and specify a specific file OR a directory of files. No curl or wget or credentials interpolation required. Exact commands syntax follows:

This code allows you to checkout a single file in a shared library that houses code called before the node block in the configured job’s 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]]
])
duncwa
  • 149
  • 1
  • 7