From a45862038982d539f5bef8d42441f1778dc36743 Mon Sep 17 00:00:00 2001 From: githubofkrishnadhas Date: Sat, 6 Jul 2024 23:45:53 +0530 Subject: [PATCH] few fixes for container crash --- Dockerfile | 4 ++-- config-as-code.yaml | 27 --------------------------- number_of_executors.groovy | 13 +++++++++++++ user.groovy | 1 + 4 files changed, 16 insertions(+), 29 deletions(-) create mode 100644 number_of_executors.groovy diff --git a/Dockerfile b/Dockerfile index 09c919c..bbdea88 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,8 +55,8 @@ RUN latest_release=$(curl -s https://api.github.com/repos/jenkinsci/plugin-insta curl -fsSL "${download_url}" -o $JENKINS_HOME/jenkins-plugin-manager.jar # copy plugins.yaml file for installing plugins using jenkins cli COPY plugins.yaml ${JENKINS_HOME}/plugins.yaml -# Copy user.groovy to /usr/share/jenkins/ref/init.groovy.d/ where will setup the default admin user and password: -COPY user.groovy /usr/share/jenkins/ref/init.groovy.d/ +# Copy user.groovy,number_of_executors.groovy to /usr/share/jenkins/ref/init.groovy.d/ where jenkins init scripts will run +COPY *.groovy /usr/share/jenkins/ref/init.groovy.d/ # Configuration as code and set as a environment variable COPY ./config-as-code.yaml $JENKINS_HOME/config-as-code.yaml ENV CASC_JENKINS_CONFIG=$JENKINS_HOME/config-as-code.yaml diff --git a/config-as-code.yaml b/config-as-code.yaml index 3710048..fad4e3b 100644 --- a/config-as-code.yaml +++ b/config-as-code.yaml @@ -8,31 +8,4 @@ credentials: id: "${GITHUB_APP_ID}" privateKey: "${GITHUB_APP_KEY}" - -# Providing default permission for users through `authenticated` group that can login to jenkins -jenkins: -# setting basic nuqmber of job executors in jenkins master as 6 - numExecutors: 6 - authorizationStrategy: - globalMatrix: - entries: - - group: - name: "authenticated" - permissions: - - "Agent/Build" - - "Agent/Configure" - - "Agent/Create" - - "Credentials/Create" - - "Credentials/Update" - - "Credentials/View" - - "Job/Build" - - "Job/Cancel" - - "Job/Configure" - - "Job/Create" - - "Job/Move" - - "Job/Read" - - "Overall/Read" - - "View/Configure" - - "View/Create" - - "View/Read" # ref https://www.roger.ml/p/jenkins-ci-github-app-authentication \ No newline at end of file diff --git a/number_of_executors.groovy b/number_of_executors.groovy new file mode 100644 index 0000000..d935256 --- /dev/null +++ b/number_of_executors.groovy @@ -0,0 +1,13 @@ +import jenkins.model.Jenkins + +// parameter to tweak default number of executors +Integer numberOfExecutors = 6 + +// get Jenkins instance +def jenkins = Jenkins.getInstance() + +// set the number of slaves +jenkins.setNumExecutors(numberOfExecutors) + +// save current Jenkins state to disk +jenkins.save() \ No newline at end of file diff --git a/user.groovy b/user.groovy index b6095d8..e68fed4 100644 --- a/user.groovy +++ b/user.groovy @@ -14,6 +14,7 @@ if(!(jenkins.getAuthorizationStrategy() instanceof GlobalMatrixAuthorizationStra def user = jenkins.getSecurityRealm().createAccount(env.JENKINS_USER, env.JENKINS_PASS) user.save() +// provide admin access to jenkins_user which is passed by user jenkins.getAuthorizationStrategy().add(Jenkins.ADMINISTER, env.JENKINS_USER) jenkins.save() \ No newline at end of file