[JIRA] (JENKINS-55630) Support declarative pipelines

4 views
Skip to first unread message

benjamin.muschko@gmail.com (JIRA)

unread,
Jan 16, 2019, 4:32:02 PM1/16/19
to jenkinsc...@googlegroups.com
Benjamin Muschko created an issue
 
Jenkins / Improvement JENKINS-55630
Support declarative pipelines
Issue Type: Improvement Improvement
Assignee: Christopher Orr
Components: golang-plugin
Created: 2019-01-16 21:31
Priority: Major Major
Reporter: Benjamin Muschko

Currently, it only seems to be possible to create a scripted pipeline for Go projects with this plugin. I was struggling to find equivalent support for modeling a declarative pipeline.

 

The issue I ran into:

 

  1. Accessing a tool in a declarative pipeline should work just fine.
  2. Defining a custom workspace is not allowed in a declarative pipeline.
  3. Setting the environment variables for different build stages is impractical. If possible those environment variables should already be preset.

 

This is how I solved the issue right now, however, Jenkins seems to move away from scripted pipelines toward declarative ones. Let me know if this is already possible.

 

node {
{{ def goHome = tool('go-1.11')}}

{{ ws("${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}/src/github.com/bmuschko/link-verifier") {}}
   withEnv(["GOROOT=${goHome}", "GOPATH=${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}/", "PATH+GO=${goHome}/bin"]) {

       ... 

{{    }}}

}

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

benjamin.muschko@gmail.com (JIRA)

unread,
Jan 16, 2019, 4:33:01 PM1/16/19
to jenkinsc...@googlegroups.com
Benjamin Muschko updated an issue
Change By: Benjamin Muschko
Currently, it only seems to be possible to create a scripted pipeline for Go projects with this plugin. I was struggling to find equivalent support for modeling a declarative pipeline.

 

The issue I ran into:

 
# Accessing a tool in a declarative pipeline should work just fine.
# Defining a custom workspace is not allowed in a declarative pipeline.
# Setting the environment variables for different build stages is impractical. If possible those environment variables should already be preset.


 

This is how I solved the issue right now, however, Jenkins seems to move away from scripted pipelines toward declarative ones. Let me know if this is already possible.

  <code>

{{
node { }}
{{ def goHome = tool('go-1.11') }}

{{
    
ws("${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}/src/github.com/bmuschko/link-verifier") { }}
{{    withEnv(["GOROOT=${goHome}", "GOPATH=${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}/", "PATH+GO=${goHome}/bin"]) { }}

{{       
...  }}

{{   
} }}

{{
} }}
</code>

benjamin.muschko@gmail.com (JIRA)

unread,
Jan 16, 2019, 4:34:02 PM1/16/19
to jenkinsc...@googlegroups.com
Benjamin Muschko updated an issue
Currently, it only seems to be possible to create a scripted pipeline for Go projects with this plugin. I was struggling to find equivalent support for modeling a declarative pipeline.

 

The issue I ran into:

 
# Accessing a tool in a declarative pipeline should work just fine.
# Defining a custom workspace is not allowed in a declarative pipeline.
# Setting the environment variables for different build stages is impractical. If possible those environment variables should already be preset.

 

This is how I solved the issue right now, however, Jenkins seems to move away from scripted pipelines toward declarative ones. Let me know if this is already possible.

< { code > }
node {
    def goHome = tool('go-1.11')
    
    ws("${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}/src/github.com/bmuschko/link-verifier") {
        withEnv(["GOROOT=${goHome}", "GOPATH=${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}/", "PATH+GO=${goHome}/bin"]) {
        ...
    }
}
</ { code > }

benjamin.muschko@gmail.com (JIRA)

unread,
Jan 16, 2019, 4:34:05 PM1/16/19
to jenkinsc...@googlegroups.com
Benjamin Muschko updated an issue
Currently, it only seems to be possible to create a scripted pipeline for Go projects with this plugin. I was struggling to find equivalent support for modeling a declarative pipeline.

 

The issue issues I ran into:

 
# Accessing a tool in a declarative pipeline should work just fine.
# Defining a custom workspace is not allowed in a declarative pipeline.
# Setting the environment variables for different build stages is impractical. If possible those environment variables should already be preset.

 

This is how I solved the issue right now, however, Jenkins seems to move away from scripted pipelines toward declarative ones. Let me know if this is already possible.

{code}
node {
    def goHome = tool('go-1.11')
    
    ws("${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}/src/github.com/bmuschko/link-verifier") {
        withEnv(["GOROOT=${goHome}", "GOPATH=${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}/", "PATH+GO=${goHome}/bin"]) {
        ...
    }
}
{code}

chris@orr.me.uk (JIRA)

unread,
Jan 17, 2019, 6:09:02 PM1/17/19
to jenkinsc...@googlegroups.com
Christopher Orr commented on Improvement JENKINS-55630
 
Re: Support declarative pipelines

Can you show the Declarative Pipeline that you tried already and are having trouble with?

The Go-related environment variables should already be exported during a Pipeline build, and so this Pipeline works fine to install Go and be able to run it:

pipeline {
  agent any
  tools {
    go '1.11'
  }
  stages {
    stage('Build') {
      steps {
        sh 'go version'
        sh 'git clone https://github.com/bmuschko/link-verifier'
        dir('link-verifier') {
          sh 'go build …'
        }
      }
    }
  }
} 

Does that cover what you're trying to do?

benjamin.muschko@gmail.com (JIRA)

unread,
Jan 17, 2019, 7:22:02 PM1/17/19
to jenkinsc...@googlegroups.com
Benjamin Muschko commented on Improvement JENKINS-55630
 
Re: Support declarative pipelines

Thanks for your response. I should have mentioned that I am using `dep` for package management.

pipeline {
    agent any
    tools {
        go 'go-1.11'
    }
    stages {
        stage('Prepare') {
            steps {
                sh 'go version'
                sh 'curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh'
                sh 'dep ensure'
            }
        }
        stage('Build') {
            steps {
                sh 'go build'
            }
        }
    }
}

When trying to run `dep ensure` I get the following error message:

+ dep ensure
/Users/bmuschko/.jenkins/workspace/link-verifier is not within a known GOPATH/src

That's why I came to the conclusion that I needed a custom workspace. Do you have another idea on how to work around the issue? Things are probably easier with `vgo` as your project source doesn't necessarily have to reside in `$GOPATH/src`.

benjamin.muschko@gmail.com (JIRA)

unread,
Jan 22, 2019, 11:48:01 AM1/22/19
to jenkinsc...@googlegroups.com
 
Re: Support declarative pipelines

FYI: I switched my project to Go modules. Go modules makes the setup much easier. You can just use a declarative pipeline definition.

benjamin.muschko@gmail.com (JIRA)

unread,
Oct 7, 2019, 10:14:02 AM10/7/19
to jenkinsc...@googlegroups.com
 
Re: Support declarative pipelines

Closing the issue as Go Modules solves the problem.

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

benjamin.muschko@gmail.com (JIRA)

unread,
Oct 7, 2019, 10:15:03 AM10/7/19
to jenkinsc...@googlegroups.com
Benjamin Muschko closed an issue as Fixed
Change By: Benjamin Muschko
Status: Open Closed
Resolution: Fixed
Reply all
Reply to author
Forward
0 new messages