Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
4c8b8d4f
Commit
4c8b8d4f
authored
Dec 27, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: add `pwd` function with working directory [GH-762]
parent
476486ef
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
2 deletions
+34
-2
CHANGELOG.md
CHANGELOG.md
+2
-0
packer/config_template.go
packer/config_template.go
+6
-0
packer/config_template_test.go
packer/config_template_test.go
+22
-0
website/source/docs/templates/configuration-templates.html.markdown
...urce/docs/templates/configuration-templates.html.markdown
+4
-2
No files found.
CHANGELOG.md
View file @
4c8b8d4f
...
...
@@ -41,6 +41,8 @@ IMPROVEMENTS:
dramatically increased.
*
core: Build names are now template processed so you can use things
like user variables in them. [GH-744]
*
core: New "pwd" function available globally that returns the working
directory. [GH-762]
*
builder/amazon/all: Launched EC2 instances now have a name of
"Packer Builder" so that they are easily recognizable. [GH-642]
*
builder/amazon/all: Copying AMIs to multiple regions now happens
...
...
packer/config_template.go
View file @
4c8b8d4f
...
...
@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"github.com/mitchellh/packer/common/uuid"
"os"
"strconv"
"text/template"
"time"
...
...
@@ -36,6 +37,7 @@ func NewConfigTemplate() (*ConfigTemplate, error) {
result
.
root
=
template
.
New
(
"configTemplateRoot"
)
result
.
root
.
Funcs
(
template
.
FuncMap
{
"pwd"
:
templatePwd
,
"isotime"
:
templateISOTime
,
"timestamp"
:
templateTimestamp
,
"user"
:
result
.
templateUser
,
...
...
@@ -97,6 +99,10 @@ func templateISOTime() string {
return
time
.
Now
()
.
UTC
()
.
Format
(
time
.
RFC3339
)
}
func
templatePwd
()
(
string
,
error
)
{
return
os
.
Getwd
()
}
func
templateTimestamp
()
string
{
return
strconv
.
FormatInt
(
InitTime
.
Unix
(),
10
)
}
...
...
packer/config_template_test.go
View file @
4c8b8d4f
...
...
@@ -2,6 +2,7 @@ package packer
import
(
"math"
"os"
"strconv"
"testing"
"time"
...
...
@@ -29,6 +30,27 @@ func TestConfigTemplateProcess_isotime(t *testing.T) {
}
}
func
TestConfigTemplateProcess_pwd
(
t
*
testing
.
T
)
{
tpl
,
err
:=
NewConfigTemplate
()
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
pwd
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
result
,
err
:=
tpl
.
Process
(
`{{pwd}}`
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
result
!=
pwd
{
t
.
Fatalf
(
"err: %s"
,
result
)
}
}
func
TestConfigTemplateProcess_timestamp
(
t
*
testing
.
T
)
{
tpl
,
err
:=
NewConfigTemplate
()
if
err
!=
nil
{
...
...
website/source/docs/templates/configuration-templates.html.markdown
View file @
4c8b8d4f
...
...
@@ -53,8 +53,10 @@ While some configuration settings have local variables specific to only that
configuration, a set of functions are available globally for use in _any string_
in Packer templates. These are listed below for reference.
*
``isotime``
- UTC time in RFC-3339 format.
*
``timestamp``
- The current Unix timestamp in UTC.
*
`pwd`
- The working directory while executing Packer.
*
`isotime`
- UTC time in RFC-3339 format.
*
`timestamp`
- The current Unix timestamp in UTC.
*
`uuid`
- Returns a random UUID.
## Amazon Specific Functions
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment