Coder Social home page Coder Social logo

Comments (15)

dcoraboeuf avatar dcoraboeuf commented on August 14, 2024 2

It's on my todo list, but I'm currently overflown with other issues :( Not Ontrack related...

from ontrack-plugin.

MorganGeek avatar MorganGeek commented on August 14, 2024 1

(initially posted into nemerosa/ontrack#574)

Hi !

While migrating from classic Jenkins jobs definition to Jenkins declarative pipeline definition, I'm looking for examples of usage of ontrack in and ontrack DSL in context of declarative pipelines.

I'm trying to create jobs parameters whose values are automatically populated by ontrack using ontrack DSL. It was possible to do so before declarative pipeline, using ontrack dsl parameter in the UI, but I didn't find an example of doing the same thing in declarative pipeline.

pipeline {
    agent any
    parameters {
        ... // how to create dynamic ontrack parameter here ?
    }
    stages {
        stage('Example') {
            steps {
                ...
            }
        }
    }
}

Is it possible ? Could you provide an example if you have any ? A solution to my particular issue or even better, a complete example of declarative pipeline making use of the full potential of ontrack could be a good helper to convice more people to use ontrack, especially since declarative pipeline is the future of jenkins jobs definition.

Thanks a lot :)

PS : I found this, didn't tested yet, need to be investigated on my side, will provide feedback if I can came up with a solution
https://stackoverflow.com/questions/44570163/jenkins-dynamic-declarative-pipeline-parameters#44626376

from ontrack-plugin.

dcoraboeuf avatar dcoraboeuf commented on August 14, 2024

@flesire

I will make an ontrack global variable available in the DSL, which will allow to code Ontrack calls using directly the DSL. For example:

node (...) {
    ...
    // Creates a build entry
    ontrack.branch('project', 'branch').build(env.BUILD_NUMBER, "Description")
}

See https://github.com/jenkinsci/docker-workflow-plugin/blob/master/src/main/java/org/jenkinsci/plugins/docker/workflow/DockerDSL.java for an example of global variable definition.

from ontrack-plugin.

dcoraboeuf avatar dcoraboeuf commented on August 14, 2024

It's on branch feature/19-pipeline but I have difficulties making it work due to difficulties with CPS constraints. I'm working on it when time allows and it should be available in the next weeks.

from ontrack-plugin.

dcoraboeuf avatar dcoraboeuf commented on August 14, 2024

As of today, I have to use code like:

@NonCPS
def mycall(ontrack) {
    ontrack.branch('test', 'master').build(env.BUILD_NUMBER as String, 'For test', true) {
        validate 'VS1'
    }
}
ontrack {
    mycall(delegate)
}
0

Pretty ugly. But I can't get my head around the CPS transformations.

from ontrack-plugin.

dcoraboeuf avatar dcoraboeuf commented on August 14, 2024

First step created: ontrackBuild... I finally gave up with the CPS transformation, and I'm using regular steps like, for example:

...
ontrackBuild(project: 'proj', branch: 'master', build: env.BUILD_NUMBER)
...

Now, trying to make some integration tests and creation other steps, including calling the Ontrack DSL (as a string)

from ontrack-plugin.

MorganGeek avatar MorganGeek commented on August 14, 2024

Current progress is : it works in declarative syntax using the following code, but I hate the result so will keep working on it.

properties([
    parameters([
        [
            $class: 'OntrackChoiceParameterDefinition', 
            description: '', 
            dsl: "ontrack.branch('APS', 'release').standardFilter(count: 5)",
            name: 'RELEASE_NUMBER', 
            valueProperty: 'name',
            sandbox: false
        ]
    ])
])
pipeline {
    agent any
   /* parameters {
        ... // how to create dynamic ontrack parameter here ?
    }*/
    stages {
        stage('Example') {
            steps {
	         echo 'deployment of config for ' + params.RELEASE_NUMBER
            }
        }
    }
}

Thanks to that I have a parametrizable build where values are filled by ontrack (see picture : https://i.imgur.com/x7Z8XWm.png )

Next challenge is to make it work with a more user friendly syntax

Tested using Jenkins 2.73.2 + ontrack plugin 2.31.1 with ontrack 2.30.4

What I would like to achieve is to define the parameters as below :

pipeline {
    agent any
    parameters {
        ontrackChoiceParam(name: 'RELEASE_NUMBER', description: '...', dsl: '...', valueProperty: '...')
    }
    stages {
        stage('Example') {
            steps {
	         echo 'deployment of config for ' + params.RELEASE_NUMBER
            }
        }
    }
}

But in order to have per-plugin parameters recognised by Jenkins, I think it's needed to define a specific Symbol in your classes that extend ParameterDefinition https://github.com/jenkinsci/ontrack-plugin/search?utf8=%E2%9C%93&q=ParameterDescriptor+&type=

Example here with the credentials plugin where a Symbol annotation is defined
https://github.com/jenkinsci/credentials-plugin/blob/master/src/main/java/com/cloudbees/plugins/credentials/CredentialsParameterDefinition.java#L115

More info about this problem and solution for credentials plugin, if it's helpful :
https://issues.jenkins-ci.org/browse/JENKINS-44588
https://github.com/jenkinsci/credentials-plugin/pull/86/files

Cheers
Morgan

from ontrack-plugin.

dcoraboeuf avatar dcoraboeuf commented on August 14, 2024

For my information, do you work with the latest build from the feature/19-pipeline-dsl branch, or do you use a released version of the plugin?

from ontrack-plugin.

MorganGeek avatar MorganGeek commented on August 14, 2024

I use the released version of plugin, with versions mentioned in the previous post

Tested using Jenkins 2.73.2 + ontrack plugin 2.31.1 with ontrack 2.30.4

from ontrack-plugin.

dcoraboeuf avatar dcoraboeuf commented on August 14, 2024

Ah ok :) Sorry. You might want to test by building the feature/19-pipeline-dsl locally and publishing the HPI in your Jenkins instance (management of dependencies can be tricky though...)

from ontrack-plugin.

MorganGeek avatar MorganGeek commented on August 14, 2024

If you already have a HPI of this version available (as I see you are using travis) I can have a look.
Otherwise I'll try to build it and test it on my side :) (cannot promise when It will be done) and keep you informed, it not urgent for you. I will also test with the Symbol annotation added

from ontrack-plugin.

dcoraboeuf avatar dcoraboeuf commented on August 14, 2024

Available in 2.32.0

from ontrack-plugin.

MorganGeek avatar MorganGeek commented on August 14, 2024

@dcoraboeuf is it possible to implement the @symbol as suggested in #19 (comment) ? I think it's needed to use ontrack build parameters in native pipeline syntax

from ontrack-plugin.

MorganGeek avatar MorganGeek commented on August 14, 2024

@dcoraboeuf started working on this, will create an issue and PR when happy with result locally ;)

from ontrack-plugin.

dcoraboeuf avatar dcoraboeuf commented on August 14, 2024

I'm looking forward to it :)

from ontrack-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.