execInContainer function
Implementation
Future<void> execInContainer({
required String name,
required String command,
required String buildJobId,
required String runId,
required String token,
}) async {
final result = await Process.run('docker', [
'exec',
name,
'bash',
'-c',
command,
]);
final stdout = result.stdout?.toString().trim();
final stderr = result.stderr?.toString().trim();
if (stdout != null && stdout.isNotEmpty) {
final masked = stdout.replaceAll(token, '***');
await logInfo(buildJobId, runId, masked);
}
if (stderr != null && stderr.isNotEmpty) {
final masked = stderr.replaceAll(token, '***');
await logInfo(buildJobId, runId, masked);
}
if (result.exitCode != 0) {
throw Exception('Command failed with exit code ${result.exitCode}');
}
}