title: Converting Jenkins Freestyle Golang Job to Jenkinsfile
body: <p>I'm trying to convert my existing Jenkins Freestyle Golang Job into a Jenkinsfile that I can check-in along with my project so I can use it in a Pipeline Job instead.</p>
  
  <p>Said job is simply running all Go tests and Building the project if all tests pass. Deployment is not yet a concern of this job.</p>
  
  <p>My working setup is as follows:</p>
  
  <p><strong><em>Go Plugin Installations:</em></strong></p>
  
  <pre><code>Name: Go
  Install Automatically: Checked
  Install from golang.org: Go 1.11.2
  </code></pre>
  
  <p><strong><em>NOTE:</em></strong> I gave it the name <code>Go</code> so the Go installation folder portion <code>Go/src</code> can be consistent in the directories below.</p>
  
  <p><strong><em>Credentials (Global):</em></strong></p>
  
  <pre><code>Username with password: (My email address and password)
  </code></pre>
  
  <p><strong><em>Job Configuration:</em></strong></p>
  
  <pre><code>Use custom workspace: Checked
      Directory: /var/lib/jenkins/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go/src/MY_PROJECT_NAME
  
  Source Code Management:
      Git
          Repository URL: MY_PRIVATE_BITBUCKET_URL.git
          Credentials: (My email address and password)
          Branches to build: */master
  
  Build Environment:
      Set up Go programming language tools: Checked
          Go version: Go
  
  Build
      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
  </code></pre>
  
  <p>I tried using the <code>Convert To Pipeline</code> plugin, but it was not able to completely convert the job:</p>
  
  <pre><code>// 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']]]) 
          }
  
          stage ('MY_PROJECT_NAME - Build') {            
              // Unable to convert a build step referring to "org.jenkinsci.plugins.golang.GolangBuildWrapper". Please verify and convert manually if required.       
              // Shell build step
              sh """ 
              cd /var/lib/jenkins/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go/src/MY_PROJECT_NAME
              go clean -cache
              go test ./... -v
              """     
              // Shell build step
              sh """ 
              cd /var/lib/jenkins/tools/org.jenkinsci.plugins.golang.GolangInstallation/Go/src/MY_PROJECT_NAME
              go build 
              """ 
          }
      }
  }
  </code></pre>
  
  <p>How do I convert this simple Job into a Jenkinsfile? I am also willing to integrate Docker into said file if necessary.</p>