Closed gprossliner closed 1 year ago
Hi @gprossliner thanks for reporting! We are working on more prioritized issues at the moment, but will get back to this one soon.
Hi @Kozlov-Igor. thank you for the answer.
agent.containermapping
var, i can run the exec itself, so I have a workaround2.170.1
, so I updated to the current version 2.202.1
(the described behavior did stay the same)This is the workaround:
- script: |
CID=$(echo "$AGENT_CONTAINERMAPPING" | jq -r ".sqlserver.id")
for i in {0..10..1}; do
docker exec $CID /opt/mssql-tools/bin/sqlcmd -U sa -Psupersecure1! -Q"SELECT @@SERVERNAME"
if [ $? -eq 0 ]; then
exit 0
fi
sleep 1
done
But it would be nice if this could be fixed. Because it's documented to work this way. Please also let me know if you need some help (tests, PR, ...)
Hi @gprossliner!
Sorry for the delayed answer.
This is not a problem with a task Bash
itself, but a combination of issues with insufficient user permissions on the MsSQL container and usage of services
alongside containers
.
Using services
in your template will initialize required containers in non-interactive mode, and further steps will be handled by the host machine instead of the target container. If you want to pass the task directly to the target container you should remove the additional services
definition from your template.
Please, notice that in this case there will be an issue with the MsSQL container initialization job, due to the specific of the azure agent - to execute tasks directly on the container, the default container user should have root permissions, however on the MsSQL image default user is mssql
. You can use options: --user 0:0
in the container definition to avoid this.
Example of the working template:
resources:
containers:
- container: sqlserver
image: mcr.microsoft.com/mssql/server:2019-latest
options: --user 0:0
env:
SA_PASSWORD: supersecure1!
ACCEPT_EULA: Y
ports:
- 1433/tcp
jobs:
- job: Tests
steps:
- task: Bash@3
target: sqlserver
inputs:
targetType: inline
script: |
for i in {0..10..1}; do
/opt/mssql-tools/bin/sqlcmd -U sa -Psupersecure1! -Q"SELECT @@SERVERNAME"
if [ $? -eq 0 ]; then
exit 0
fi
sleep 1
done
echo Giving up after 10 retries, but it can work ...
Hi @vmapetr!
Sorry for the delayed response. Because I had the workaround in place, I have not checked the issue again.
Using services in your template will initialize required containers in non-interactive mode, ... you should remove the additional services definition from your template.
If I have no service, would it still be possible to execute queries against the SQL Server? Currently I use it like:
variables:
connectionstring: UID=sa;SERVER=localhost,$(agent.services.sqlserver.ports.1433);PWD=supersecure1!;
- task: DotNetCoreCLI@2
displayName: Run Tests
inputs:
command: 'test'
projects: '**/*.Test.csproj'
arguments: -c Release -e TESTS_CONNECTION_STRING="$(connectionstring)"
Without a service
, how can I access the port like agent.services.sqlserver.ports.1433
?
This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days
Required Information
Question, Bug, or Feature?
Type: Bug
Enter Task Name: Bash@3,
Environment
Server:
TFS on-premises
If using TFS on-premises, provide the version:
Version Dev18.M170.6
Agent - Hosted or Private:
uname -a: Linux lnx-adsagent-1 3.10.0-1160.59.1.el7.x86_64 #1 SMP Wed Feb 23 16:47:03 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
2.170.1
Issue Description
This is an example of the pipeline, showing the issue:
The
Bash@3
task doesn't execute in thetarget: sqlserver
container, but in the host. It is not ignored completely. If I pass in an invalid name likesqlserver_error
, an error is returned (A container resource with name sqlserver_error could not be found. The container resource does not exist...
)Checking the logs, there is no indication that the task actually tries to execute anything in the container. I expected the script to be execute as
docker exec ID ...
.As you see within the logs, the error
/opt/mssql-tools/bin/sqlcmd: No such file or directory
occurs. There is nosqlcmd
on the agent.Task logs
Can you tell what's wrong here? Or am I doing something wrong?
Thank you!