Debug groovy script within a container












1















I'm building a jenkins container and want to set the KeycloakSecurityRealm in the initial flow. I already have a script which works fine for default settings:



    import hudson.*
import hudson.model.*
import jenkins.*
import jenkins.model.*
import java.util.logging.Logger
import hudson.security.*
import java.util.*
import com.michelin.cio.hudson.plugins.rolestrategy.*
import java.lang.reflect.*

import org.jenkinsci.plugins

/*
NOTE: that megascript should be split someday, when my groovy skills improves.
*/

Thread.start {
//vbles definition
def logger = Logger.getLogger("")
def instance = Jenkins.getInstance()
def pm = instance.getPluginManager()
def uc = instance.getUpdateCenter()
def installed = false
// More code...

//No plugins to update. Security can be set
logger.info("All plugins are up to date")
logger.info("Setting security")

// logger.info("Creating initial user")
// hudsonRealm.createAccount("USER","USER")

logger.info("Creating reaml")
def keycloakSecurityRealm = keycloakRealm.createSecurityComponents()

//realm based on jenkins database
logger.info("Setting Security realm to KEYCLOAK")
instance.setSecurityRealm(keycloakSecurityRealm)

//not anonymous read allowed


This code crashes without any information. I whould like to debug the container so I've checked I can run the step where the container crashes to attach an interactive console:



enter image description here



Can do



docker run -ti 3ed


And I have access to the container as root.



Problem is I can't debug the script. I've checked there are some ways as using jdb but in all cases it is neccessary a mail java class for running it. The original script worked when called without changes so it runs file without any classes.



How could I debug this kind of java scripts inside a container?



Thanks.










share|improve this question




















  • 1





    Please do not tag your question with java when your question is about groovy. You attract the wrong experts by doing this :)

    – Joe C
    Jan 1 at 18:24
















1















I'm building a jenkins container and want to set the KeycloakSecurityRealm in the initial flow. I already have a script which works fine for default settings:



    import hudson.*
import hudson.model.*
import jenkins.*
import jenkins.model.*
import java.util.logging.Logger
import hudson.security.*
import java.util.*
import com.michelin.cio.hudson.plugins.rolestrategy.*
import java.lang.reflect.*

import org.jenkinsci.plugins

/*
NOTE: that megascript should be split someday, when my groovy skills improves.
*/

Thread.start {
//vbles definition
def logger = Logger.getLogger("")
def instance = Jenkins.getInstance()
def pm = instance.getPluginManager()
def uc = instance.getUpdateCenter()
def installed = false
// More code...

//No plugins to update. Security can be set
logger.info("All plugins are up to date")
logger.info("Setting security")

// logger.info("Creating initial user")
// hudsonRealm.createAccount("USER","USER")

logger.info("Creating reaml")
def keycloakSecurityRealm = keycloakRealm.createSecurityComponents()

//realm based on jenkins database
logger.info("Setting Security realm to KEYCLOAK")
instance.setSecurityRealm(keycloakSecurityRealm)

//not anonymous read allowed


This code crashes without any information. I whould like to debug the container so I've checked I can run the step where the container crashes to attach an interactive console:



enter image description here



Can do



docker run -ti 3ed


And I have access to the container as root.



Problem is I can't debug the script. I've checked there are some ways as using jdb but in all cases it is neccessary a mail java class for running it. The original script worked when called without changes so it runs file without any classes.



How could I debug this kind of java scripts inside a container?



Thanks.










share|improve this question




















  • 1





    Please do not tag your question with java when your question is about groovy. You attract the wrong experts by doing this :)

    – Joe C
    Jan 1 at 18:24














1












1








1








I'm building a jenkins container and want to set the KeycloakSecurityRealm in the initial flow. I already have a script which works fine for default settings:



    import hudson.*
import hudson.model.*
import jenkins.*
import jenkins.model.*
import java.util.logging.Logger
import hudson.security.*
import java.util.*
import com.michelin.cio.hudson.plugins.rolestrategy.*
import java.lang.reflect.*

import org.jenkinsci.plugins

/*
NOTE: that megascript should be split someday, when my groovy skills improves.
*/

Thread.start {
//vbles definition
def logger = Logger.getLogger("")
def instance = Jenkins.getInstance()
def pm = instance.getPluginManager()
def uc = instance.getUpdateCenter()
def installed = false
// More code...

//No plugins to update. Security can be set
logger.info("All plugins are up to date")
logger.info("Setting security")

// logger.info("Creating initial user")
// hudsonRealm.createAccount("USER","USER")

logger.info("Creating reaml")
def keycloakSecurityRealm = keycloakRealm.createSecurityComponents()

//realm based on jenkins database
logger.info("Setting Security realm to KEYCLOAK")
instance.setSecurityRealm(keycloakSecurityRealm)

//not anonymous read allowed


This code crashes without any information. I whould like to debug the container so I've checked I can run the step where the container crashes to attach an interactive console:



enter image description here



Can do



docker run -ti 3ed


And I have access to the container as root.



Problem is I can't debug the script. I've checked there are some ways as using jdb but in all cases it is neccessary a mail java class for running it. The original script worked when called without changes so it runs file without any classes.



How could I debug this kind of java scripts inside a container?



Thanks.










share|improve this question
















I'm building a jenkins container and want to set the KeycloakSecurityRealm in the initial flow. I already have a script which works fine for default settings:



    import hudson.*
import hudson.model.*
import jenkins.*
import jenkins.model.*
import java.util.logging.Logger
import hudson.security.*
import java.util.*
import com.michelin.cio.hudson.plugins.rolestrategy.*
import java.lang.reflect.*

import org.jenkinsci.plugins

/*
NOTE: that megascript should be split someday, when my groovy skills improves.
*/

Thread.start {
//vbles definition
def logger = Logger.getLogger("")
def instance = Jenkins.getInstance()
def pm = instance.getPluginManager()
def uc = instance.getUpdateCenter()
def installed = false
// More code...

//No plugins to update. Security can be set
logger.info("All plugins are up to date")
logger.info("Setting security")

// logger.info("Creating initial user")
// hudsonRealm.createAccount("USER","USER")

logger.info("Creating reaml")
def keycloakSecurityRealm = keycloakRealm.createSecurityComponents()

//realm based on jenkins database
logger.info("Setting Security realm to KEYCLOAK")
instance.setSecurityRealm(keycloakSecurityRealm)

//not anonymous read allowed


This code crashes without any information. I whould like to debug the container so I've checked I can run the step where the container crashes to attach an interactive console:



enter image description here



Can do



docker run -ti 3ed


And I have access to the container as root.



Problem is I can't debug the script. I've checked there are some ways as using jdb but in all cases it is neccessary a mail java class for running it. The original script worked when called without changes so it runs file without any classes.



How could I debug this kind of java scripts inside a container?



Thanks.







docker jenkins groovy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 18:40







Joss

















asked Jan 1 at 18:17









JossJoss

190316




190316








  • 1





    Please do not tag your question with java when your question is about groovy. You attract the wrong experts by doing this :)

    – Joe C
    Jan 1 at 18:24














  • 1





    Please do not tag your question with java when your question is about groovy. You attract the wrong experts by doing this :)

    – Joe C
    Jan 1 at 18:24








1




1





Please do not tag your question with java when your question is about groovy. You attract the wrong experts by doing this :)

– Joe C
Jan 1 at 18:24





Please do not tag your question with java when your question is about groovy. You attract the wrong experts by doing this :)

– Joe C
Jan 1 at 18:24












1 Answer
1






active

oldest

votes


















2














Once inside container, make sure to run your code in debug mode.



java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=32887 ...


In case you have no chance to start java by yourself, you can always use _JAVA_OPTIONS



export _JAVA_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=32887


Attach your debugger (e.g. IntelliJ) to remote machine (your Docker based container). Debug the code from the IDE started outside the container.



It should do the trick.



For a sample (used for profiling) take a look here:



https://github.com/mkowsiak/ProfilerDocker



It's not the same thing, but it's similar in a sense that Docker based code (Java) is executed inside container, while profiler (running outside container) is attached to remote machine.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997817%2fdebug-groovy-script-within-a-container%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Once inside container, make sure to run your code in debug mode.



    java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=32887 ...


    In case you have no chance to start java by yourself, you can always use _JAVA_OPTIONS



    export _JAVA_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=32887


    Attach your debugger (e.g. IntelliJ) to remote machine (your Docker based container). Debug the code from the IDE started outside the container.



    It should do the trick.



    For a sample (used for profiling) take a look here:



    https://github.com/mkowsiak/ProfilerDocker



    It's not the same thing, but it's similar in a sense that Docker based code (Java) is executed inside container, while profiler (running outside container) is attached to remote machine.






    share|improve this answer






























      2














      Once inside container, make sure to run your code in debug mode.



      java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=32887 ...


      In case you have no chance to start java by yourself, you can always use _JAVA_OPTIONS



      export _JAVA_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=32887


      Attach your debugger (e.g. IntelliJ) to remote machine (your Docker based container). Debug the code from the IDE started outside the container.



      It should do the trick.



      For a sample (used for profiling) take a look here:



      https://github.com/mkowsiak/ProfilerDocker



      It's not the same thing, but it's similar in a sense that Docker based code (Java) is executed inside container, while profiler (running outside container) is attached to remote machine.






      share|improve this answer




























        2












        2








        2







        Once inside container, make sure to run your code in debug mode.



        java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=32887 ...


        In case you have no chance to start java by yourself, you can always use _JAVA_OPTIONS



        export _JAVA_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=32887


        Attach your debugger (e.g. IntelliJ) to remote machine (your Docker based container). Debug the code from the IDE started outside the container.



        It should do the trick.



        For a sample (used for profiling) take a look here:



        https://github.com/mkowsiak/ProfilerDocker



        It's not the same thing, but it's similar in a sense that Docker based code (Java) is executed inside container, while profiler (running outside container) is attached to remote machine.






        share|improve this answer















        Once inside container, make sure to run your code in debug mode.



        java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=32887 ...


        In case you have no chance to start java by yourself, you can always use _JAVA_OPTIONS



        export _JAVA_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=32887


        Attach your debugger (e.g. IntelliJ) to remote machine (your Docker based container). Debug the code from the IDE started outside the container.



        It should do the trick.



        For a sample (used for profiling) take a look here:



        https://github.com/mkowsiak/ProfilerDocker



        It's not the same thing, but it's similar in a sense that Docker based code (Java) is executed inside container, while profiler (running outside container) is attached to remote machine.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 1 at 18:45

























        answered Jan 1 at 18:35









        Oo.oOOo.oO

        4,97931224




        4,97931224
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997817%2fdebug-groovy-script-within-a-container%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            Npm cannot find a required file even through it is in the searched directory

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith