Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-71975

to add enabledTTY for container(name:'name', shell: 'sh')

      When I launch pipeline in container with cmd: bash --init-file /mer-bash-setup -i, pipeline is writing error.

      I need that pod exec in k8s will with enabledTTY

      My Jenkinsfile

       

      podTemplate(yaml: '''
                    apiVersion: v1
                    kind: Pod
                    metadata:
                      annotations:
                        container.apparmor.security.beta.kubernetes.io/linux: unconfined
                    spec:
                      containers:
                      - name: linux
                        image: harbor.example.com/project-build-linux:4.0.2.249-1
                        imagePullPolicy: Always
                        securityContext:
                          runAsUser: 1000
                          runAsGroup: 1000
                          capabilities:
                            add:
                            - SYS_ADMIN
                        command:
                        - sleep
                        args:
                        - 99d
                        resources:
                          limits:
                            cpu: 16
                            memory: 8Gi
                          requests:
                            cpu: 8
                            memory: 4Gi
                      imagePullSecrets:
                      - name: harbor-registry-secret
      '''
        ) {
        node(POD_LABEL) {
          stage('Build linux version') {
            container(name: 'linux') {
              sh '''
                  bash --init-file /mer-bash-setup -i
              '''
            }
          }
        }
      }
      

       

      Error:

      [Pipeline] sh
      + bash --init-file /mer-bash-setup -i
      bash: cannot set terminal process group (213): Inappropriate ioctl for device
      bash: no job control in this shell

          [JENKINS-71975] to add enabledTTY for container(name:'name', shell: 'sh')

          The error you're encountering, "bash: cannot set terminal process group," may be because the bash command is trying to allocate a pseudo-terminal (PTY), but it's running in a non-interactive shell within your Jenkins pipeline.

          To resolve this, you could maybe use the script step in your Jenkins pipeline to run your desired commands in an interactive shell context.

          podTemplate(yaml: '''
                        apiVersion: v1
                        kind: Pod
                        metadata:
                          annotations:
                            container.apparmor.security.beta.kubernetes.io/linux: unconfined
                        spec:
                          containers:
                          - name: linux
                            image: harbor.example.com/project-build-linux:4.0.2.249-1
                            imagePullPolicy: Always
                            securityContext:
                              runAsUser: 1000
                              runAsGroup: 1000
                              capabilities:
                                add:
                                - SYS_ADMIN
                            command:
                            - sleep
                            args:
                            - 99d
                            resources:
                              limits:
                                cpu: 16
                                memory: 8Gi
                              requests:
                                cpu: 8
                                memory: 4Gi
                          imagePullSecrets:
                          - name: harbor-registry-secret
          '''
            ) {
            node(POD_LABEL) {
              stage('Build linux version') {
                container(name: 'linux') {
                  script {
                    sh '''
                        bash --init-file /mer-bash-setup -i
                    '''
                  }
                }
              }
            }
          }
           

          By wrapping your sh command in the script block, you're creating an interactive context for your bash command, which should resolve the "Inappropriate ioctl for device" error. This should allow your pod to execute the bash command with TTY enabled.

          Bruno Verachten added a comment - The error you're encountering, "bash: cannot set terminal process group," may be because the bash command is trying to allocate a pseudo-terminal (PTY), but it's running in a non-interactive shell within your Jenkins pipeline. To resolve this, you could maybe use the script step in your Jenkins pipeline to run your desired commands in an interactive shell context. podTemplate(yaml: '''               apiVersion: v1               kind: Pod               metadata:                 annotations:                   container.apparmor.security.beta.kubernetes.io/linux: unconfined               spec:                 containers:                 - name: linux                   image: harbor.example.com/project-build-linux:4.0.2.249-1                   imagePullPolicy: Always                   securityContext:                     runAsUser: 1000                     runAsGroup: 1000                     capabilities:                       add:                       - SYS_ADMIN                   command:                   - sleep                   args:                   - 99d                   resources:                     limits:                       cpu: 16                       memory: 8Gi                     requests:                       cpu: 8                       memory: 4Gi                 imagePullSecrets:                 - name: harbor-registry-secret '''   ) {   node(POD_LABEL) {     stage( 'Build linux version' ) {       container(name: 'linux' ) {         script {           sh '''               bash --init-file /mer-bash-setup -i           '''         }       }     }   } } By wrapping your sh command in the script block, you're creating an interactive context for your bash command, which should resolve the "Inappropriate ioctl for device" error. This should allow your pod to execute the bash command with TTY enabled.

          Alexander added a comment -

          Thanks, it's work. This example not solved problem for me, but take idea for solving.

          Alexander added a comment - Thanks, it's work. This example not solved problem for me, but take idea for solving.

            iocanel Ioannis Canellos
            kemaritsu Alexander
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: