Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf7ccfa2

Browse files
authored
feat: SetCODER=true in workspaces (#3637)
Fixes#2340
1 parent8343a4f commitf7ccfa2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

‎agent/agent.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
394394
iferr!=nil {
395395
returnnil,xerrors.Errorf("getting os executable: %w",err)
396396
}
397+
// Set environment variables reliable detection of being inside a
398+
// Coder workspace.
399+
cmd.Env=append(cmd.Env,"CODER=true")
400+
397401
cmd.Env=append(cmd.Env,fmt.Sprintf("USER=%s",username))
398402
// Git on Windows resolves with UNIX-style paths.
399403
// If using backslashes, it's unable to find the executable.

‎agent/agent_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,26 @@ func TestAgent(t *testing.T) {
232232
require.Equal(t,expect,strings.TrimSpace(string(output)))
233233
})
234234

235+
t.Run("Coder env vars",func(t*testing.T) {
236+
t.Parallel()
237+
238+
for_,key:=range []string{"CODER"} {
239+
key:=key
240+
t.Run(key,func(t*testing.T) {
241+
t.Parallel()
242+
243+
session:=setupSSHSession(t, agent.Metadata{})
244+
command:="sh -c 'echo $"+key+"'"
245+
ifruntime.GOOS=="windows" {
246+
command="cmd.exe /c echo %"+key+"%"
247+
}
248+
output,err:=session.Output(command)
249+
require.NoError(t,err)
250+
require.NotEmpty(t,strings.TrimSpace(string(output)))
251+
})
252+
}
253+
})
254+
235255
t.Run("StartupScript",func(t*testing.T) {
236256
t.Parallel()
237257
tempPath:=filepath.Join(t.TempDir(),"content.txt")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp