Skip to content

Commit 47528cf

Browse files
authored
pipelines install-pipelines-cli: overwrite broken symlink pointing to old DB versions (#3356)
## Changes Remove old symlink and add it pointing to new DB CLi . ## Why When installing pipelines CLI after you have updated databricks, you would still have the old symlink from pipelines CLI installed on your machine. If that is the case, when you run install-pipelines-cli, the old symlink would be overwritten to point to the new version of the DB CLI. ## Tests Updated install-pipelines-cli symlink test.
1 parent 2798377 commit 47528cf

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

acceptance/pipelines/install-pipelines-cli/output.txt

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
=== install pipelines cli
33
>>> [CLI] install-pipelines-cli -d ./subdir
4-
pipelines successfully installed in directory "./subdir"
4+
found existing pipelines installation at subdir/pipelines. Pipelines is successfully reinstalled in directory "./subdir"
55

66
>>> ./subdir/pipelines
77
Pipelines CLI
@@ -45,6 +45,43 @@ Exit code: 1
4545

4646
=== databricks executable called with alias
4747
>>> ./subdir/notdatabricks install-pipelines-cli -d ./subdir
48+
found existing pipelines installation at subdir/pipelines. Pipelines is successfully reinstalled in directory "./subdir"
49+
50+
>>> ./subdir/pipelines
51+
Pipelines CLI
52+
53+
Usage:
54+
pipelines [command]
55+
56+
Available Commands:
57+
auth Authentication related commands
58+
completion Generate the autocompletion script for the specified shell
59+
deploy Deploy pipelines
60+
destroy Destroy a pipelines project
61+
dry-run Validate correctness of the pipeline's graph
62+
help Help about any command
63+
init Initialize a new pipelines project
64+
open Open a pipeline in the browser
65+
run Run a pipeline
66+
stop Stop a pipeline
67+
version Retrieve information about the current version of the Pipelines CLI
68+
69+
Flags:
70+
--debug enable debug logging
71+
-h, --help help for pipelines
72+
-o, --output type output type: text or json (default text)
73+
-p, --profile string ~/.databrickscfg profile
74+
-t, --target string project target to use (if applicable)
75+
--var strings set values for variables defined in project config. Example: --var="foo=bar"
76+
-v, --version version for pipelines
77+
78+
Use "pipelines [command] --help" for more information about a command.
79+
80+
=== overwrites broken symlink pointing to databricks
81+
>>> ./subdir/olddatabricks install-pipelines-cli -d ./subdir
82+
found existing pipelines installation at subdir/pipelines. Pipelines is successfully reinstalled in directory "./subdir"
83+
84+
>>> [CLI] install-pipelines-cli -d ./subdir
4885
pipelines successfully installed in directory "./subdir"
4986

5087
>>> ./subdir/pipelines

acceptance/pipelines/install-pipelines-cli/script

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,13 @@ title "databricks executable called with alias"
1919
cp $CLI $tmpdir/notdatabricks
2020
trace $tmpdir/notdatabricks install-pipelines-cli -d $tmpdir
2121
trace $pipelines
22+
rm -f $pipelines
23+
24+
title "overwrites broken symlink pointing to databricks"
25+
cp -L $CLI $tmpdir/olddatabricks
26+
trace $tmpdir/olddatabricks install-pipelines-cli -d $tmpdir
27+
rm -f $tmpdir/olddatabricks
28+
trace $CLI install-pipelines-cli -d $tmpdir
29+
trace $pipelines
2230

2331
rm -rf $tmpdir/notdatabricks $pipelines $tmpdir

cmd/pipelines/install_pipelines_cli.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9+
"runtime"
10+
"strings"
911

1012
"github.com/databricks/cli/libs/cmdio"
1113
"github.com/spf13/cobra"
@@ -36,12 +38,25 @@ func installPipelinesSymlink(ctx context.Context, directory string) error {
3638
if err != nil {
3739
return err
3840
}
39-
cmdio.LogString(ctx, fmt.Sprintf("pipelines successfully installed in directory %q", dir))
41+
cmdio.LogString(ctx, fmt.Sprintf("found existing pipelines installation at %s. Pipelines is successfully reinstalled in directory %q", pipelinesPath, dir))
4042
return nil
4143
}
4244

4345
target, err := filepath.EvalSymlinks(pipelinesPath)
4446
if err != nil {
47+
if strings.Contains(err.Error(), "databricks") &&
48+
(strings.Contains(err.Error(), "no such file or directory") || (runtime.GOOS == "windows" && strings.Contains(err.Error(), "The system cannot find the file specified"))) {
49+
err = os.Remove(pipelinesPath)
50+
if err != nil {
51+
return err
52+
}
53+
err = os.Symlink(realPath, pipelinesPath)
54+
if err != nil {
55+
return err
56+
}
57+
cmdio.LogString(ctx, fmt.Sprintf("pipelines successfully installed in directory %q", dir))
58+
return nil
59+
}
4560
return err
4661
}
4762
if realPath == target {

0 commit comments

Comments
 (0)