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:

  • Setting .htcaccess in an external volume for Docker not working
  • Docker: Unable to view running container despite successful demo example
  • Pass “volume-driver” option to kubernetes pod
  • What are the possibilities to debug a docker swarm?
  • Docker Containers on Marathon disappeared
  • Docker: Why is /etc/resolv.conf unreadable? Breaks DNS [closed]
  • 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

  • Why does sendmail cli not send mails from docker containers?
  • Docker doesn't resolve hostname
  • ManageIQ web application inside docker container can’t connect to Hawkular outside container
  • docker stop and remove container
  • Access NFS files from Docker
  • Nginx fail on Docker deployment to Amazon
  • 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.