亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 Jenkins Freestyle Golang 作業轉換為 Jenkinsfile

將 Jenkins Freestyle Golang 作業轉換為 Jenkinsfile

Go
慕桂英4014372 2023-05-08 15:06:25
我正在嘗試將我現有的 Jenkins Freestyle Golang 作業轉換為 Jenkinsfile,我可以將其與我的項目一起簽入,以便我可以在管道作業中使用它。所述工作只是運行所有 Go 測試并在所有測試通過后構建項目。部署還不是這項工作的關注點。我的工作設置如下:Go 插件安裝:Name: GoInstall Automatically: CheckedInstall from golang.org: Go 1.11.2注意:我給它起的名字Go是為了讓 Go 安裝文件夾部分Go/src在下面的目錄中保持一致。憑證(全球):Username with password: (My email address and password)職位配置:Use custom workspace: Checked    Directory: /var/lib/jenkins/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go/src/MY_PROJECT_NAMESource Code Management:    Git        Repository URL: MY_PRIVATE_BITBUCKET_URL.git        Credentials: (My email address and password)        Branches to build: */masterBuild Environment:    Set up Go programming language tools: Checked        Go version: GoBuild    Execute Shell        # Remove cached test results.        go clean -cache                    # Run all Go tests.        cd /var/lib/jenkins/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go/src/MY_PROJECT_NAME        go test ./... -v    Execute Shell        # Build the project.        cd /var/lib/jenkins/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go/src/MY_PROJECT_NAME        go build我嘗試使用該Convert To Pipeline插件,但它無法完全轉換作業:// Powered by Infostretch timestamps {    node () {                stage ('MY_PROJECT_NAME - Checkout') {            checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'MY_CREDENTIALS_ID', url: 'MY_PRIVATE_BITBUCKET_URL.git']]])         }如何將這個簡單的作業轉換為 Jenkinsfile?如有必要,我也愿意將 Docker 集成到所述文件中。
查看完整描述

1 回答

?
森林海

TA貢獻2011條經驗 獲得超2個贊

我想到了。


Jenkinsfile以下是我位于項目目錄根目錄中的內容:


#!/usr/bin/env groovy

// The above line is used to trigger correct syntax highlighting.


pipeline {

    agent { docker { image 'golang' } }    


    stages {

        stage('Build') {                

            steps {      

                // Create our project directory.

                sh 'cd ${GOPATH}/src'

                sh 'mkdir -p ${GOPATH}/src/YOUR_PROJECT_DIRECTORY'


                // Copy all files in our Jenkins workspace to our project directory.                

                sh 'cp -r ${WORKSPACE}/* ${GOPATH}/src/YOUR_PROJECT_DIRECTORY'


                // Copy all files in our "vendor" folder to our "src" folder.

                sh 'cp -r ${WORKSPACE}/vendor/* ${GOPATH}/src'


                // Remove build cache.

                sh 'go clean -cache'


                // Build the app.

                sh 'go build'

            }            

        }


        // Each "sh" line (shell command) is a step,

        // so if anything fails, the pipeline stops.

        stage('Test') {

            steps {

                // Remove cached test results.

                sh 'go clean -testcache'


                // Run all Tests.

                sh 'go test ./... -v'                    

            }

        }

    }

}


查看完整回答
反對 回復 2023-05-08
  • 1 回答
  • 0 關注
  • 172 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號