我要评分
获取效率
正确性
完整性
易理解

Jenkins Pipeline Compilation Sample Code

To use BiSheng Compiler or GCC for openEuler capabilities, use the following sample code:

A-FOT (Configuration File Parameter Optimization)

pipeline {
    agent any
    options {
        timeout(time: 1, unit: 'HOURS')
        }
    parameters {
        string(name: 'GIT_URL', defaultValue: 'https://gitee.com/devkit-pipeline/c_demo.git', description: '--> git url <--')
        string(name: 'GIT_BRANCH', defaultValue: 'master', description: '--> code branch <--')
        string(name: 'GIT_TARGET_DIR_NAME', defaultValue: 'c_demo', description: '--> code branch <--')
    }
    stages{
        stage('Git   Code') {
            agent {
                label 'kunpeng_scanner'
            }
            steps {
                echo '====== Obtaining the source code ======'
                checkout scmGit(branches: [[name: "${params.GIT_BRANCH}"]],
                                browser: github("${params.GIT_URL}"),
                                extensions: [[$class: 'RelativeTargetDirectory',
                                relativeTargetDir: "${params.GIT_TARGET_DIR_NAME}"],
                                cleanBeforeCheckout(deleteUntrackedNestedRepositories: true)],
                                userRemoteConfigs: [[url: "${params.GIT_URL}"]])
            }
        }
        stage('build') {
            agent {
                # To use BiSheng Compiler capabilities, set label to kunpeng_c_builder_bisheng_compiler.
                label 'kunpeng_c_builder_gcc'
            }
            steps {
                script{
                    sh '''
                        source ${HOME}/.local/wrap-bin/devkit_NonInvasiveSwitching.sh
                        cd ./c_demo
                        make
                    '''
                }
            }               
        }
    }
    stages{
        stage('A-FOT') {
            agent {
                label 'kunpeng_c_builder_gcc'
            }
            steps{               
                # After the installation is complete, the GCC for openEuler environment is available. The compilation commands are the same as those on other platforms.
                ####################################
                # Replace it with the actual compilation command. #
                ####################################
                sh 'a-fot --config_file a-fot.ini'
            }
        }
    }
}

A-FOT (Command Line Parameter Optimization)

pipeline {
    agent any
    options {
        timeout(time: 1, unit: 'HOURS')
    }
    parameters {
        string(name: 'GIT_URL', defaultValue: 'https://gitee.com/devkit-pipeline/c_demo.git', description: '--> git url <--')
        string(name: 'GIT_BRANCH', defaultValue: 'master', description: '--> code branch <--')
        string(name: 'GIT_TARGET_DIR_NAME', defaultValue: 'c_demo', description: '--> code branch <--')
    }
    stages{
        stage('Git Code') {
            steps {
                echo '====== Obtaining the source code ======'
                checkout scmGit(branches: [[name: "${params.GIT_BRANCH}"]],
                                    browser: github("${params.GIT_URL}"),
                                    extensions: [[$class: 'RelativeTargetDirectory',
                                    relativeTargetDir: "${params.GIT_TARGET_DIR_NAME}"],
                                    cleanBeforeCheckout(deleteUntrackedNestedRepositories: true)],
                                    userRemoteConfigs: [[url: "${params.GIT_URL}"]])
            }
        }
        stage('build') {
            agent {
                # To use BiSheng Compiler capabilities, set label to kunpeng_c_builder_bisheng_compiler.
                label 'kunpeng_c_builder_gcc'
            }
            steps {
                script{
                   sh '''
                        source ${HOME}/.local/wrap-bin/devkit_NonInvasiveSwitching.sh
                        cd ./c_demo
                        make
                    '''
                }
            }
        }
    }
    stages{
        stage('A-FOT') {
            agent {
                label 'kunpeng_c_builder_gcc'
            } 
            steps{
                sh 'a-fot --opt_mode AutoFDO --gcc_path /usr --run_script /root/run.sh --build_script /root/build.sh --build_mode Wrapper --work_path ./ --bin_file /tmp/test'
            } 
        }
    }
}

The optimization mode is AutoFDO, the GCC path is /usr, the application running script path is /root/run.sh, the application build script path is /root/build.sh, the build mode is Wrapper, and the script working directory is the current directory, and the executable binary path is /tmp/test. Replace them with the actual ones.