简体   繁体   中英

Jenkins pipeline from SCM -> always complete rebuild

for our jenkins build server, I use a pipeline script which was until now only in jenkins. Now I moved the pipeline script onto our git server.

The jenkins project and your application is building fine, but: before pipeline the move to git, the build of your C++ application was "incremental", so only new changes were built. Therefore a manual triggered build was quite fast.

Now with the pipeline in git, jenkins/msbuild does always a complete rebuild, but I do not get why. Th full rebuild needs about 30min.

Below is my shorted code of our pipeline.

Did anyone observe such a behaviour? Or any idea why msbuild means it must do a complete rebuild?

Thanks in advance, Jonas

pipeline 
{
    stages
    {
        stage('Checkout from Github') { ... }
        stage('CppCheck') { ... }
        stage('Generate Doxygen Documentation') { ... }
        stage('Version read') { ... }
        stage('Cmake Repo Preparations') { ... }
        stage('Build x64')
        {
            steps
            {
                dir('build')
                {
                     // MSBuild command line parameters:
                     // /m: parallel build with as many cores as the CPU has
                     bat '"C:/Program Files (x86)/MSBuild/14.0/Bin/amd64/MSBuild.exe" project.sln /p:configuration=release /p:platform=x64 /m'
                }
            }
        }
        stage('Create installer') { ... }
        stage('Archive') { ... }
        stage('Deploy to NFS') { .. }
    }
    post { ... }
}

This questions is already one year old but I want to share our investigations since we stumbled into the same problem and observed the following on Jenkins v.235.2 .

The first command which is executed on the agent is "Pipeline from SCM" the stage which is visible is the "Declarative SCM Checkout" in the pipeline stages overview. So this command will download the Jenkinsfile which contains the pipeline instructions to the respective Jenkins workspace on the agent. By executing this command and downloading the Jenkinsfile it creates a ".git" folder in your agent's job root workspace (eg C:\\jenkins\\workspace\\jobA\\.git). Since you now fetch your source code, in order to build your software, into the same workspace location the ".git" folder itself will be overwritten / replaced. Deleting the metadata of the ".git" folder results in a new clean fetch and software build. Also this can lead to some strange behavior of Git itself.

From our investigations you have two options to fix this (maybe there are more but this helped us).

  1. Keep the job root workspace for fetching the Jenkinsfile and download the source code into another folder eg dir('src') { git clone ... } .

or possibility two what we've implemented now in our pipelines.

  1. From the Jenkins Documentation it's mentioned:

skipDefaultCheckout Skip checking out code from source control by default in the agent directive. For example: options { skipDefaultCheckout() }

This command will prevent downloading the Jenkinsfile on the agent instead it's checked out on the Jenkins master itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM