0

Currently we are developing centralized control system for our CI/CD projects. There are many projects with many branches so we are using multibranch pipeline ( This forces us to use Jenkinsfile from project branches so we can't provide custom Jenkinsfile like Pipeline projects ). We want to control everything under 1 git repo where for every project there should be kubernetes YAMLS's, Dockerfile and Jenkinsfile. When developer presses build button, Jenkinsfile from their project repo suppose to run our jenkinsfile. Is it possible to do this?

E.g. :

pipeline {
    agent any
    stages {
        stage('Retrieve Jenkinsfile From Repo') { // RETRIEVE JENKINSFILE FROM REPO
            steps {
                git branch: "master",
                credentialsId: 'gitlab_credentials',
                url: "jenkinsfile_repo"
                
                scripts {
                
                  // RUN JENKINSFILE FROM THE REPO
            
                }
            }
    
        }
    }
}

Main reason we are doing this, there are sensetive context in jenkinsfile like production database connections. We don't want to store jenkinsfile under developers' repo. Also you can suggest correct way to achieve that beside using only 1 repo.

EDIT: https://plugins.jenkins.io/remote-file/

This plugin solved all my problems. I could'not try comments below

Emre Kiratli
  • 357
  • 3
  • 14
  • I can propose you another approach: May be you have to trigger another pipeline from this one? Basically I think you approach is not possible, because of conflicts: for example you may have defined different agents inside of JENKINSFILES. When you are inside a stage you are already on a working agent, so you can't run another pipeline and define again all the CI process – Bulikeri Jul 24 '20 at 13:30

2 Answers2

0

As an option you can use pipeline build step.

pipeline {
    agent any
    stages {
        stage ('build another job') {
            steps {
                build 'second_job_name_here'
            }
        }
    }
}
0

Try load step

scripts {
  // rename Jenkinsfile to .groovy
  sh 'mv Jenkinsfile Jenkins.groovy'
                
  // RUN JENKINSFILE FROM THE REPO
  load 'Jenkinsfile.groovy'
            
}
yong
  • 11,757
  • 1
  • 10
  • 23