apiVersion: v1
kind: ConfigMap
metadata:
  name: jenkins-synergy-configurations
  namespace: jenkins-prod
data:
  1-configure-theme.groovy: | 
    import jenkins.*
    import jenkins.model.*
    import hudson.*
    import hudson.model.*
    import org.jenkinsci.plugins.simpletheme.ThemeElement
    import org.jenkinsci.plugins.simpletheme.CssTextThemeElement
    import org.jenkinsci.plugins.simpletheme.CssUrlThemeElement

    Jenkins jenkins = Jenkins.getInstance()

    def decorator = Jenkins.instance.getDescriptorByType(org.codefirst.SimpleThemeDecorator.class)

    List<ThemeElement> configElements = new ArrayList<>();
    configElements.add(new CssTextThemeElement("DEFAULT"));
    configElements.add(new CssUrlThemeElement("https://cdn.rawgit.com/afonsof/jenkins-material-theme/gh-pages/dist/material-light-green.css"));
    decorator.setElements(configElements);
    decorator.save();

    jenkins.save()
  2-system-message.yaml: |
    jenkins:
      systemMessage: "Hello to brand new EOSC-synergy jenkins!"
  3-configure-github-auth.yaml: |
    jenkins:
      securityRealm:
        github:
          githubWebUri: "https://github.com"
          githubApiUri: "https://api.github.com"
          clientID: "${jenkins-incd-github-EOSCsynergyOAuth-clientID}"
          clientSecret: "${jenkins-incd-github-EOSCsynergyOAuth-clientSecret}"
          oauthScopes: "read:org,user:email,repo"
  4-configure-github-authorization.yaml: |
    jenkins:
      authorizationStrategy:
        gitHub:
          adminUserNames: "jenkins-operator, tiagofglip, samuelbernardolip"
          organizationNames: "EOSC-synergy"
          authenticatedUserReadPermission: false
          useRepositoryPermissions: false
          authenticatedUserCreateJobPermission: false
          allowGithubWebHookPermission: true
          allowCcTrayPermission: false
          allowAnonymousReadPermission: false
          allowAnonymousJobStatusPermission: false
  5-configure-github-plugin.yaml: |
    credentials:
      system:
        domainCredentials:
          - credentials:
              - string:
                  scope: SYSTEM
                  id: github_jenkins_incd_token
                  secret: ${GITHUB_JENKINS_INCD_TOKEN} # github personal access token
    unclassified:
      location:
        url: https://jenkins2.a.incd.pt/
        adminAddress: jenkins-incd@lip.pt
      gitHubPluginConfig:
        configs:
        - name: "server1"
          apiUrl: https://api.github.com
          credentialsId: github_jenkins_incd_token
          clientCacheSize:
          manageHooks: true
        