Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline plugin compatibility (Formerly Workflow plugin) #92

Closed
leth opened this issue Jan 20, 2016 · 31 comments
Closed

Pipeline plugin compatibility (Formerly Workflow plugin) #92

leth opened this issue Jan 20, 2016 · 31 comments

Comments

@leth
Copy link

leth commented Jan 20, 2016

I'd be great if we could use this plugin from a Jenkinsfile!

The plugin repo has a compatibility guide.

@scaytrase
Copy link
Member

How does this handle credentials?

@leth
Copy link
Author

leth commented Jan 20, 2016

It looks like they reference them by ID, e.g:

git url: 'git@git.local.domain:ps/project.git', credentialsId: '67c3072d-b9a7-44fa-a5aa-560ba9c1662f'

@jglick
Copy link
Member

jglick commented Feb 24, 2016

Probably suffices to implement SimpleBuildStep and replace AbstractBuild with Run everywhere, skipping calls to TokenMacro if not in fact passed an AbstractBuild.

@lindt
Copy link

lindt commented Apr 13, 2016

is there any known possible workaround?

Something like?

sh 'curl https://stash..../foo'

@scaytrase
Copy link
Member

Sure, yes, you could just use official stash\bitbucket server documentation

https://developer.atlassian.com/stash/docs/latest/how-tos/updating-build-status-for-commits.html

@stchar
Copy link

stchar commented Apr 15, 2016

Hi,
Does anyone is working on this? If not please assign it to me

@stchar
Copy link

stchar commented Apr 29, 2016

BTW @scaytrase,
whats the target branch should be? master or relase1.0 I see some refactoring on the master but new classes are not currently in use.

@scaytrase
Copy link
Member

Use default branch (release/1.x currently) as target

@stchar
Copy link

stchar commented Apr 29, 2016

To all who are interested in.

I believe that the usage of stash notifier plugin in pipeline should be changed.
I think that behavior can be same as in the email plugin.
You can notify stash any time with any status for any repository you want.

So you add a step in the beginning of the build section and insert

step([$class: 'StashNotifier', buildState: 'INPROGRESS', commitSha1: 'bbbb', credentialsId: '', disableInprogressNotification: false, ignoreUnverifiedSSLPeer: false, includeBuildNumberInKey: false, prependParentProjectKey: false, projectKey: 'cccc', stashServerBaseUrl: 'aaaa'])

On failure you just catch the error
like

stage 'build'
try {
     sh 'do the build'
} catch (e) {
     step([$class: 'StashNotifier', buildState: 'FAILED', commitSha1: 'bbbb', credentialsId: '', disableInprogressNotification: false, ignoreUnverifiedSSLPeer: false, includeBuildNumberInKey: false, prependParentProjectKey: false, projectKey: 'cccc', stashServerBaseUrl: 'aaaa'])
     error e
}

On success you send

step([$class: 'StashNotifier', buildState: 'SUCCESS', commitSha1: 'bbbb', credentialsId: '', disableInprogressNotification: false, ignoreUnverifiedSSLPeer: false, includeBuildNumberInKey: false, prependParentProjectKey: false, projectKey: 'cccc', stashServerBaseUrl: 'aaaa'])

Overall the snippet generator might look like this
image

I'm free for any other ideas. Just let me know.

@scaytrase
Copy link
Member

Could you post a sample build file to represent the case-branching model (inprogress, fail, success)

@stchar
Copy link

stchar commented Apr 29, 2016

@scaytrase, sure, will do it later. Now I have to get back to work.

@scaytrase
Copy link
Member

Okey, just wan't to see how it will look like to give opinion. I've personally dislike the idea to store so much information in scripts (too much coupling to the infrastructue)

@nickbroon
Copy link

There appears to be Github Commit Status Notifier step that seems very similar, that can can be used from the Snippet editor.

step([$class: 'GitHubCommitStatusSetter', commitShaSource: [$class: 'ManuallyEnteredShaSource', sha: '123456'], statusResultSource: [$class: 'ConditionalStatusResultSource', results: [[$class: 'AnyBuildResult', message: 'Foo Bar', state: 'FAILURE']]]])

https://github.com/jenkinsci/github-plugin/blob/master/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java

It would probably be good to model it on that.

@stchar
Copy link

stchar commented May 11, 2016

@scaytrase
I keep in mind following snippet:

node('master') {
    _WORKSPACE=pwd()
    for ( repository in ['repository1', 'repository2', 'repository3'] ) {

        stage repository+'-verification'    // repository1-verification

        dir(_WORKSPACE+'/'+repository) {

             git "https://mybb.org/project/${repository}.git"

             // Somehow get commit sha1             
             notify(repository,'aabbcc','INPROGRESS')

             try {
                 echo 'do the build/test/whatever'
             } catch (e) {
                   notify(repository,'aabbcc','FAILED')
               error e
             }
             notify(repository,'aabbcc','SUCCESS')
         }
    }
}

def notify(repository,sha1,status) {
    step([$class: 'StashNotifier', 
    buildState: status, 
    commitSha1: sha1, 
    credentialsId: '1111-2222-3333-4444', 
    disableInprogressNotification: false, 
    ignoreUnverifiedSSLPeer: false, 
    includeBuildNumberInKey: false, 
    prependParentProjectKey: false, 
    projectKey: 'myproject',
    repositoryKey: repository,     // new argument as it's not clear how to get git url in workflow
    stashServerBaseUrl: 'https://mybb.org'])
 }

@scaytrase
Copy link
Member

repositoryKey: repository, // new argument as it's not clear how to get git url in workflow

What for? StashBaseUrl + CommitSha1 should be enought to notify.

@Faheetah
Copy link

How do we even derive the commit hash from pipelines? JENKINS-34455 gives a workaround using shell but pipelines don't expose a commit hash variable from what I can see, even though the job recognizes one.

@scaytrase
Copy link
Member

When building classic build steps, commit sha1 is known from the ENV. When using suggested

 git "https://mybb.org/project/${repository}.git"

it could be obtained from workdir, i think

@tmds
Copy link

tmds commented May 13, 2016

@headcrabmeat, any idea when we can expect this feature?

@tmds
Copy link

tmds commented May 18, 2016

Is someone working on this issue? Is there a workaround?

@scaytrase
Copy link
Member

Workaround is proposed to pipeline plugin

jenkinsci/pipeline-examples#21

@stchar
Copy link

stchar commented May 18, 2016

@tmds
It's hard to say. I still do not have a working code. All I can say is that I'm motivated to implement it's asap, as I want to use a plugin instead of workaround.

@tmds
Copy link

tmds commented May 18, 2016

@headcrabmeat good to hear you are still on the issue! Depending on where you are it may be usefull to initiate a pull request and get some feedback even if things aren't working yet.

@stchar
Copy link

stchar commented May 18, 2016

@tmds, @scaytrase,
Created PR #108.
Comments are welcome.

@tmds
Copy link

tmds commented May 23, 2016

@scaytrase can you review the PR?

@scaytrase
Copy link
Member

I think there is nothing to review until tests pass. Everything could change. I'm keeping eye on it, don't worry. The patch is full of temporary changes, I think @headcrabmeat let us know when he is ready

@tmds
Copy link

tmds commented May 27, 2016

@scaytrase
Copy link
Member

Not the best example, as for me. Very platform dependent, requires sh, git in path (Jenkins has jgit as option), creates temporary files

@tmds
Copy link

tmds commented May 27, 2016

Not the best example, as for me. Very platform dependent, requires sh, git in path (Jenkins has jgit as option), creates temporary files

Only example so far and good as a starting point.

@stchar
Copy link

stchar commented May 27, 2016

Thanks guys, I was told that env object can be used as well. I will try it soon.

@coder-hugo
Copy link

I implemented such a build step a few weeks ago for the gitlab-plugin. You can have a look at the GitLabCommitStatusStep as an example how to do this.

@scaytrase
Copy link
Member

Implemented with #115

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants