apiVersion: v1
kind: ConfigMap
metadata:
  name: tavros-jenkins-config
  namespace: jenkins
data:
  1-casc.yaml: |
    unclassified:
      location:
        url: https://ci.tavros.example.com/
        adminAddress: ops@example.com
      keycloakSecurityRealm:
        keycloakJson: |-
          {
            "realm": "prod",
            "auth-server-url": "https://auth.tavros.example.com/auth/",
            "ssl-required": "external",
            "resource": "jenkins",
            "public-client": true,
            "confidential-port": 0
          }
      giteaServers:
        servers:
        - credentialsId: "tavros-gitea-creds"
          displayName: "gitea"
          manageHooks: true
          serverUrl: "https://code.tavros.example.com"
      globalLibraries:
        libraries:
          - name: "tavros-library"
            defaultVersion: "v0.2"
            retriever:
              modernSCM:
                scm:
                  git:
                    remote: "https://github.com/MS3Inc/tavros-jenkins-libraries.git"
    jenkins:
      securityRealm: keycloak
      globalNodeProperties:
      - envVars:
          env:
          - key: TAVROS_GIT_HOST
            value: code.tavros.example.com
          - key: TAVROS_GIT_PROVIDER
            value: gitea
          - key: TAVROS_GIT_CREDS
            value: tavros-gitea-creds

    jobs:
    - script: >
        organizationFolder('Gitea Tavros Folder') {
            description("Track Tavros Gitea repositories and events")
            displayName('Gitea Tavros')
            organizations {
            }

            configure { node ->
                // todo: setup auto scan every 30 mins
                node / navigators << 'org.jenkinsci.plugin.gitea.GiteaSCMNavigator' {
                    serverUrl("https://code.tavros.example.com")
                    repoOwner("tavros")
                    credentialsId("tavros-gitea-creds")
                    traits {
                        'org.jenkinsci.plugin.gitea.BranchDiscoveryTrait'() {
                            strategyId('1')
                        }
                        'org.jenkinsci.plugin.gitea.OriginPullRequestDiscoveryTrait'() {
                            strategyId('1')
                        }
                        'org.jenkinsci.plugin.gitea.ForkPullRequestDiscoveryTrait'() {
                            strategyId('1')
                            trust(class: 'org.jenkinsci.plugin.gitea.ForkPullRequestDiscoveryTrait\$TrustContributors')
                        }
                    }
                }
            }
        }
    - script: >
        pipelineJob('Quickstart \u2212 OpenAPI Project') {
          definition {
            cps {
              sandbox(true)
              script("""@Library("tavros-library") _
                        |
                        |openapi_quickstart()""".stripMargin())
            }
          }
        }
    - script: >
        pipelineJob('Quickstart \u2212 Camel Web Service Project') {
          definition {
            cps {
              sandbox(true)
              script("""@Library("tavros-library") _
                        |
                        |camelwebservice_quickstart()""".stripMargin())
            }
          }
        }
