jenkinsci / gogs-webhook-plugin

Jenkins Gogs Webhook
https://plugins.jenkins.io/gogs-webhook/
MIT License
79 stars 42 forks source link

GOGS_REF can't be found in Jenkinsfile #43

Closed yvolodym closed 6 years ago

yvolodym commented 6 years ago

Description

GOGS_REF can't be found in Jenkinsfile (Multibranch Pipeline): stages { stage('Info') { steps { echo "GOGS_REF: " + env.GOGS_REF } }

Output in console: GOGS_REF: null

sanderv32 commented 6 years ago

Did you enable 'Build when a change is pushed to Gogs'? Without it to environment variables are not set.

yvolodym commented 6 years ago

i changed project from multibranch to pipeline project and activate "Build when a change is pushed to Gogs". Output is the same GOGS_REF: null

sanderv32 commented 6 years ago

@ketyboss The current implementation in the plugin doesn't work properly with the Jenkinsfile. Will release this is the next version of the plugin.

yvolodym commented 6 years ago

Thanks for information! I'm looking forward to the new release!

sanderv32 commented 6 years ago

@ketyboss You can try to test drive the last snapshot version which can be downloaded here. This version exposes all except the arraylist to environment variables.

yvolodym commented 6 years ago

Hi. Plugin 1.0.15-SNAPSHOT (private-c49bd6c8-jenkins) Send from Gogs:

{
  "ref": "refs/heads/master",
  "before": "cb0b65cc80ef8b3030533c6fddc9c17a496f4d67",
  "after": "cb0b65cc80ef8b3030533c6fddc9c17a496f4d67",
  "compare_url": "",
  "commits": [
    {
      "id": "cb0b65cc80ef8b3030533c6fddc9c17a496f4d67",
      "message": "set private smtp port to 250\n",

Jenkinsfile:

  stages {
        stage('Info') {
            steps {
                echo "GOGS_REF: " + env.GOGS_REF
                echo "BRANCH_NAME: " + env.BRANCH_NAME
                echo "BUILD_NUMBER: " + env.BUILD_NUMBER
            }
        }

Output from Jenkins (Maven Project)

[Pipeline] stage
[Pipeline] { (Info)
[Pipeline] echo
GOGS_REF: null
[Pipeline] echo
BRANCH_NAME: null
[Pipeline] echo
BUILD_NUMBER: 14
[Pipeline] }
[Pipeline] // stage

"Build when a change is pushed to Gogs" ist activ Sorry it's not work properly...

sanderv32 commented 6 years ago

Try this in your steps: echo sh(script: 'env|sort', returnStdout: true)

yvolodym commented 6 years ago

It works! But only if the project is set up as a multibranch project. If that is as Maven then there are no GOGS variables in output Multibranch:

GOGS_AFTER=6ea33861ffeee0469663b6ded9320472f7a85657
GOGS_BEFORE=a38c16f435dbb85a10de01e4fce4ac44205a1528
GOGS_COMPARE_URL=https://git.myurl.de/myproject/myproject/compare/a38c16f435dbb85a10de01e4fce4ac44205a1528...6ea33861ffeee0469663b6ded9320472f7a85657
GOGS_PUSHER_AVATAR_URL=https://secure.gravatar.com/avatar/bec6438bb6486860
GOGS_PUSHER_EMAIL=eugen@myurl.de
GOGS_PUSHER_FULL_NAME=Eugen
GOGS_PUSHER_LOGIN=mylogin
GOGS_PUSHER_USERNAME=myusername
GOGS_REF=refs/heads/master
GOGS_REPOSITORY_CLONE_URL=https://git.myurl.de/myproject/myproject.git
GOGS_REPOSITORY_CREATED_AT=2017-10-29T19:10:22+01:00
GOGS_REPOSITORY_DEFAULT_BRANCH=master
GOGS_REPOSITORY_DESCRIPTION=My Repository
GOGS_REPOSITORY_EMPTY=false
GOGS_REPOSITORY_FORK=false
GOGS_REPOSITORY_FULL_NAME=myproject/myproject
GOGS_REPOSITORY_HTML_URL=https://git.myurl.de/myproject/myproject
GOGS_REPOSITORY_MIRROR=false
GOGS_REPOSITORY_NAME=myproject
GOGS_REPOSITORY_OWNER_AVATAR_URL=https://git.myurl.de/avatars/4
GOGS_REPOSITORY_OWNER_FULL_NAME=myproject GmbH
GOGS_REPOSITORY_OWNER_LOGIN=myproject
GOGS_REPOSITORY_OWNER_USERNAME=myproject
GOGS_REPOSITORY_PRIVATE=true
GOGS_REPOSITORY_SSH_URL=ssh://git@git.myurl.de/myproject/myproject.git
GOGS_REPOSITORY_UPDATED_AT=2018-05-14T08:27:39+02:00
GOGS_REPOSITORY_WEBSITE=http://www.myproject.de
GOGS_SENDER_AVATAR_URL=https://secure.gravatar.com/avatar/bec6438bb64868600
GOGS_SENDER_EMAIL=eugen@myurl.de
GOGS_SENDER_FULL_NAME=Eugen
GOGS_SENDER_LOGIN=mylogin
GOGS_SENDER_USERNAME=myusername
HOME=/root

Maven Project - empty blok of GOGS