Jenkins shell script add Unix user to group

I am running two consecutive shell scripts in a Jenkinsfile:

stage('running scripts') {
    sh "sudo script1.sh"
    sh "groups && whoami"
}

script1.sh:

  • Caching Jar dependencies for Maven-based Docker builds
  • Docker linux: How to start multiple console/terminals for one running container?
  • How do we set the the RAM and disk space for a docker container?
  • Docker container migration
  • Unable to remove tag of a docker image due to 'no such image' error
  • Error starting docker postgres on travis-
  • groupadd docker
    usermod -aG docker ubuntu
    groups ubuntu
    

    Console output is:

    ubuntu : ubuntu adm dialout cdrom floppy sudo audio dip video plugdev netdev lxd docker
    

    But second shell script (i.e: sh "groups && whoami") shows that ubuntu user is NOT in docker group:

    + groups
    ubuntu adm dialout cdrom floppy sudo audio dip video plugdev netdev lxd
    + whoami
    ubuntu
    

    What am I doing wrong ?
    Thanks

  • Django & Docker : manage dependencies between production & dev environment
  • How to add 3rd party jar to maven container docker
  • How to install tshark on Docker?
  • Node not found in alpine docker
  • Import qcow2 image to docker hub
  • Automatic self-configuration of an etcd cluster as a Docker swarm service
  • One Solution collect form web for “Jenkins shell script add Unix user to group”

    Group permissions apply on login, and jenkins doesn’t rerun the login between steps of the pipeline. I’d recommend adding the group to your build slave (or docker image for your build slave).

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.