How do I use docker to compile code in Jenkins?

problem description

I want to use Docker container in Jenkins to compile the code.
is to trigger automatic compilation of Jenkins every time push commit is added to the github.

the platform version of the problem and what methods you have tried

I am currently using pipeline, but from log it seems that I am not using Docker to compile the code.

related codes

/ / Please paste the code text below (do not replace the code with pictures)
Jenkinsfile

pipeline {
    agent none
    stages {
        stage("Build") {
            agent {
                docker { image "zequanhannto/tina" }
            }
            steps {
                sh "echo $PWD"
                sh "source build/envsetup.sh"
                sh "lunch astar_parrot-tina"
                sh "make -j"
                sh "pack -d"
            }
        }
        stage("Test") {
            steps {
                echo "Testing.."
            }
        }
        stage("Deploy") {
            steps {
                echo "Deploying...."
            }
        }
    }
}

Jenkins build log:

Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] node
Running on Jenkins in /root/.jenkins/workspace/tina-pipeline
[Pipeline] {
[Pipeline] sh
[tina-pipeline] Running shell script
+ docker inspect -f . zequanhannto/tina
.
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 0:0 -w /root/.jenkins/workspace/tina-pipeline -v /root/.jenkins/workspace/tina-pipeline:/root/.jenkins/workspace/tina-pipeline:rw,z -v /root/.jenkins/workspace/tina-pipeline@tmp:/root/.jenkins/workspace/tina-pipeline@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** zequanhannto/tina cat
$ docker top f2049aa68d08f2c3fd548d2cabe8b6aae779db26a98f72b2e83146b51206405c -eo pid,comm
[Pipeline] {
[Pipeline] sh
[tina-pipeline] Running shell script
+ echo /root/jenkins
/root/jenkins
[Pipeline] sh
[tina-pipeline] Running shell script
+ source build/envsetup.sh
/root/.jenkins/workspace/tina-pipeline@tmp/durable-5556332e/script.sh: 2: /root/.jenkins/workspace/tina-pipeline@tmp/durable-5556332e/script.sh: source: not found
[Pipeline] }
$ docker stop --time=1 f2049aa68d08f2c3fd548d2cabe8b6aae779db26a98f72b2e83146b51206405c
$ docker rm -f f2049aa68d08f2c3fd548d2cabe8b6aae779db26a98f72b2e83146b51206405c
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Test)
Stage "Test" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy)
Stage "Deploy" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE

what result do you expect? What is the error message actually seen?

I added an echo $PWD and the result is the folder above my host. When I use agent in Jenkinsfile, aren"t all steps running in the new docker container? How to solve it?

Mar.28,2021
Menu