@@ -47,8 +47,12 @@ pub fn get_all_scripts(dir: &Path) -> Result<Vec<Script>, errors::Error> {
4747
4848#[ cfg_attr( test, mockable) ]
4949impl Script {
50- #[ instrument( level = "info" , name = "script.run" , fields( task. name = %self . name, task. path = %self . path. display( ) ) , err, skip( self ) ) ]
51- pub fn run ( & self , config : & HashMap < String , String > ) -> Result < ( ) , errors:: Error > {
50+ #[ instrument( level = "info" , name = "script.run" , fields( task. name = %self . name, task. path = %self . path. display( ) ) , err, skip( self , secrets) ) ]
51+ pub fn run (
52+ & self ,
53+ config : & HashMap < String , String > ,
54+ secrets : & HashMap < String , String > ,
55+ ) -> Result < ( ) , errors:: Error > {
5256 let extension = match self . path . extension ( ) {
5357 Some ( ext) => ext. to_str ( ) . ok_or ( errors:: user (
5458 & format ! ( "Unable to parse the file extension used by the task file '{}'" , self . path. display( ) ) ,
@@ -58,12 +62,17 @@ impl Script {
5862 & format ! ( "Could not determine how to run the task file '{}' because it did not have a file extension." , self . path. display( ) ) ,
5963 "Use one of the supported file extensions to tell buckle how to execute this task file." ) ) ?
6064 } ;
65+
66+ let mut config = config. clone ( ) ;
67+ for ( key, val) in secrets {
68+ config. insert ( key. clone ( ) , val. into ( ) ) ;
69+ }
6170
6271 match extension {
63- "ps1" => run_script_task ( "pwsh" , config, & self . path ) ?,
64- "sh" => run_script_task ( "bash" , config, & self . path ) ?,
65- "bat" => run_script_task ( "cmd.exe" , config, & self . path ) ?,
66- "cmd" => run_script_task ( "cmd.exe" , config, & self . path ) ?,
72+ "ps1" => run_script_task ( "pwsh" , & config, & self . path ) ?,
73+ "sh" => run_script_task ( "bash" , & config, & self . path ) ?,
74+ "bat" => run_script_task ( "cmd.exe" , & config, & self . path ) ?,
75+ "cmd" => run_script_task ( "cmd.exe" , & config, & self . path ) ?,
6776 _ => Err ( errors:: user (
6877 & format ! (
6978 "The '{}' extension is not supported for task files." ,
@@ -78,11 +87,15 @@ impl Script {
7887}
7988
8089#[ cfg_attr( test, mockable) ]
81- #[ instrument( name = "command.run" , fields( stdout, stderr) , skip( config) , err) ]
82- pub fn run_script_task ( interpreter : & str , config : & HashMap < String , String > , file : & Path ) -> Result < ( ) , errors:: Error > {
90+ #[ instrument( name = "command.run" , fields( stdout, stderr) , skip( env) , err) ]
91+ pub fn run_script_task (
92+ interpreter : & str ,
93+ env : & HashMap < String , String > ,
94+ file : & Path ,
95+ ) -> Result < ( ) , errors:: Error > {
8396 process:: Command :: new ( interpreter)
8497 . arg ( file)
85- . envs ( config )
98+ . envs ( env )
8699 . output ( )
87100 . map_err ( |err| errors:: user_with_internal (
88101 & format ! ( "Failed to execute the command '{} {}'." , interpreter, file. display( ) ) ,
0 commit comments