Search code examples
linuxazureazure-storageazure-batch

Installing JDK to a pool's compute nodes in Azure Batch


I have to install java on the Ubuntu server nodes in my pool. I am trying to do it by tasks but every time I try to install java through the task using below code :

 TaskAddParameter taskToAdd = new TaskAddParameter();
    taskToAdd.withId(taskId).withCommandLine(String.format("sudo apt-get install openjdk-8-jdk"));
    // Associate resource file with task
    taskToAdd.withResourceFiles(getListOfResourceFiles(sas));

I get an error saying

sudo: no tty present and no askpass program specified

I tried the above way at Pool Level also by giving this command in the StartTask of the Pool but then also it gave me the same error.

I need to install java on my pool nodes so that I can run my java program on it.


Solution

  • You should do this on the pool's StartTask.

    For the commandLine you need to invoke a shell as described in the best practices guide here. So instead of:

    sudo apt-get install openjdk-8-jdk
    

    do:

    /bin/bash -c "sudo apt-get install openjdk-8-jdk"
    

    Additionally, you should use the PoolAdmin AutoUser user identity so you do not have to invoke sudo. Please see this guide for more information.