0
votes

To summerize the issue, I have git repository for example called Repo_A.
Repo_A contains:

Repo_A:
---> release-pipeline.gdsl
---> src/
---> pom.xml

release-pipeline.gdsl content:

node(params.node) {
    stage('Build Source Code') {
        sh 'pwd'
        sh 'ls -l'
        sh 'mvn clean compile package'
    }
}

The output of the stage is the following (Jenkins project name Repo_A_CI_Project):

Started by user MyUser
Obtained release-pipeline.gdsl from git [email protected]:Repo_A.git
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on myServer in /home/MyHome/jenkins_agent/workspace/Repo_A_CI_Project
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Build Source Code)
[Pipeline] sh
+ pwd
/home/MyHome/jenkins_agent/workspace/Repo_A_CI_Project
[Pipeline] sh
+ ls -l
total 0
[Pipeline] sh
+ mvn clean compile package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.735 s
[INFO] Finished at: 2019-10-20T09:26:34+00:00
[INFO] Final Memory: 25M/1963M
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/home/MyHome/jenkins_agent/workspace/Repo_A_CI_Project). Please verify you invoked Maven from the correct directory. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 0s
ERROR: script returned exit code 1
Finished: FAILURE

The problem here is that Jenkins Pipeline doens't clone the whole Repo_A repository contents. It's only obtain the gdsl file release-pipeline.gdsl.

The job is pipeline type, I already set the right config for this project and what is the git repo should pull it.

Previously it was working without issue and pull the whole repo and consider the execution place on the root of the repo to start execute stage's commands.

As you can see from the log, I used ls -l to view the content and it show 0 content.

[Pipeline] sh
+ ls -l
total 0
[Pipeline]

I expect to see like that

[Pipeline] sh
+ ls
release-pipeline.gdsl src/ pom.xml
[Pipeline]

in Jenkins log, the only thing that I see is this simple message.

org.jenkinsci.plugins.githubautostatus.GithubNotificationConfig log
INFO: Could not find commit sha - status will not be provided for this build

I'm using this approach since it's simple to pull the Jenkins build file (release-pipeline.gdsl) as well as the other content of repo to build directly without extra steps.

Appreciate your help.

1

1 Answers

1
votes

In all likelihood, you have selected the Lightweight checkout checkbox in the job configuration page.

enter image description here

If selected, try to obtain the Pipeline script contents directly from the SCM without performing a full checkout.

Just clear the checkbox and you should be good to go.

Edit

The above method works in Declarative Pipelines to automatically checkout the source code in a stage if options { skipDefaultCheckout() } is not used. So, it does not hold good for this question, which concerns a Scripted Pipeline.

In Scripted Pipelines, Jenkins by default may not necessarily checkout the repository in the same node where you run your stage. In that case you need to call the step checkout scm in your stage (which uses the SCM configured in the Pipeline section of the job) and leave the Lightweight checkout checkbox selected to avoid checking out twice.

Also, you can call the sh step with ''' for multiline commands instead of calling it thrice.

node(params.node) {
    stage('Build Source Code') {
        checkout scm
        sh '''
            pwd'
            ls -l
            mvn clean compile package
        '''
    }
}