opendevstack / ods-jenkins-shared-library

Shared Jenkins library which all ODS projects & components use - provisioning, SonarQube code scanning, Nexus publishing, OpenShift template based deployments and repository orchestration
Apache License 2.0
73 stars 57 forks source link

Make ODS pipeline configurable for MRO #97

Closed ungerts closed 5 years ago

ungerts commented 5 years ago

Multi repository orchestration (MRO) requires to checkout an ODS component/repository within a top level pipeline and to load/execute its Jenkinsfile dynamically. Example:

dir('componentId') {
   git url: '<REPO_URL>'     // checkout ODS component
   load path: 'Jenkinsfile'  // load and execute Jenkinsfile of ODS component
}

In order to allow orchestration the ODS pipeline should be more configurable:

PoC (working in progress) can be found here: https://github.com/ungerts/ods-jenkins-shared-library/tree/experimental/mro

michaelsauter commented 5 years ago

Plan sounds good đź‘Ť

ungerts commented 5 years ago

Implemented first version which allows me to run following Jenkinsfile for testing:

def final projectId = 'project13'
def final componentId = 'component123'
def final credentialsId = "${projectId}-cd-cd-user-with-password"
def sharedLibraryRepository
def dockerRegistry
def multiRepoBuild

node {
  sharedLibraryRepository = env.SHARED_LIBRARY_REPOSITORY
  dockerRegistry = env.DOCKER_REGISTRY
  multiRepoBuild = !!env.MULTI_REPO_BUILD
}

library identifier: 'ods-library@production', retriever: modernSCM(
        [$class: 'GitSCMSource',
         remote: sharedLibraryRepository,
         credentialsId: credentialsId])

def configMap = [
        image: "${dockerRegistry}/cd/jenkins-slave-golang",
        projectId: projectId,
        componentId: componentId,
        branchToEnvironmentMapping: [
                'master': 'test',
                '*': 'dev'
        ]
]

if (multiRepoBuild) {
  configMap.displayNameUpdateEnabled = false
  configMap.localCheckoutEnabled = false
  configMap.bitbucketNotificationEnabled = false
  configMap.ciSkipEnabled = false
  configMap.cloneSourceEnv = false
}

odsPipeline(configMap) { context ->
  //...
}
ungerts commented 5 years ago

Assumption ist that a MRO sets an environment variable called _MULTI_REPOBUILD

michaelsauter commented 5 years ago

Hmm - what do you think about hiding all of this inside the shared lib? You can read the environment variables inside (we only read SHARED_LIBRARY_REPOSITORY and DOCKER_REGISTRY because we need them before we have the shared lib), and then you can disable inside the lib. That way, we do not need to touch all the Jenkinsfiles out there and we do not need to have all this extra code in each file, making it hard to update.

ungerts commented 5 years ago

Yes, I think in that direction, too. My only counter argument is that in this case we access a "magic variable" (MULTI_REPO_BUILD) that does not exist in ODS at the moment.

Am Mi., 17. Juli 2019 um 17:19 Uhr schrieb Michael Sauter < notifications@github.com>:

Hmm - what do you think about hiding all of this inside the shared lib? You can read the environment variables inside (we only read SHARED_LIBRARY_REPOSITORY and DOCKER_REGISTRY because we need them before we have the shared lib), and then you can disable inside the lib. That way, we do not need to touch all the Jenkinsfiles out there and we do not need to have all this extra code in each file, making it hard to update.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/opendevstack/ods-jenkins-shared-library/issues/97?email_source=notifications&email_token=AALWPCXENP6OCRJWP2IDON3P742AHA5CNFSM4IEAG3J2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2EWQ2Q#issuecomment-512321642, or mute the thread https://github.com/notifications/unsubscribe-auth/AALWPCQSNZ6D6IHFQCRJVKTP742AHANCNFSM4IEAG3JQ .

michaelsauter commented 5 years ago

I'm okay with that. Maybe allow to also "enable MRO mode" by setting an option.

ungerts commented 5 years ago

@michaelsauter Found a solution that both is possible

ungerts commented 5 years ago

@michaelsauter @metmajer @tjaeschke how do we handle branch to environment mapping in MRO builds?

Options:

clemensutschig commented 5 years ago

+1 for option 2

michaelsauter commented 5 years ago

I'd also let the orchestrating pipeline control where things should be deployed.

ungerts commented 5 years ago

Implemented option 2

ungerts commented 5 years ago

Implemented approach:

Assumptions, Limitations, Deviations

MRO build configuration

michaelsauter commented 5 years ago

If I understand correctly, this has been merged by now by another PR. Closing this - @ungerts reopen if you think this is not completed yet.