2929import hudson .Launcher ;
3030import hudson .model .Run ;
3131import hudson .model .TaskListener ;
32- import hudson .slaves .WorkspaceList ;
3332import hudson .util .Secret ;
3433import org .jenkinsci .Symbol ;
3534import org .jenkinsci .plugins .credentialsbinding .BindingDescriptor ;
@@ -93,7 +92,8 @@ public String getPassphraseVariable() {
9392
9493 @ Override public MultiEnvironment bind (Run <?,?> build , FilePath workspace , Launcher launcher , TaskListener listener ) throws IOException , InterruptedException {
9594 SSHUserPrivateKey sshKey = getCredentials (build );
96- FilePath keyFile = tempDir (workspace ).child ("ssh-key-" + keyFileVariable );
95+ UnbindableDir keyDir = UnbindableDir .create (workspace );
96+ FilePath keyFile = keyDir .getDirPath ().child ("ssh-key-" + keyFileVariable );
9797
9898 StringWriter stringWriter = new StringWriter ();
9999 PrintWriter keysFileStream = new PrintWriter (stringWriter );
@@ -120,28 +120,7 @@ public String getPassphraseVariable() {
120120 map .put (usernameVariable , sshKey .getUsername ());
121121 }
122122
123- return new MultiEnvironment (map , new KeyRemover (keyFile .getRemote ()));
124- }
125-
126- private static class KeyRemover implements MultiBinding .Unbinder {
127-
128- private static final long serialVersionUID = 1 ;
129-
130- private final String filePath ;
131-
132- KeyRemover (String filePath ) {
133- this .filePath = filePath ;
134- }
135-
136- @ Override public void unbind (Run <?, ?> build , FilePath workspace , Launcher launcher , TaskListener listener ) throws IOException , InterruptedException {
137- workspace .child (this .filePath ).delete ();
138- }
139-
140- }
141-
142- // TODO 1.652 use WorkspaceList.tempDir
143- private static FilePath tempDir (FilePath ws ) {
144- return ws .sibling (ws .getName () + System .getProperty (WorkspaceList .class .getName (), "@" ) + "tmp" );
123+ return new MultiEnvironment (map , keyDir .getUnbinder ());
145124 }
146125
147126 @ Symbol ("sshUserPrivateKey" )
0 commit comments